summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-08-16 16:07:47 +0200
committerYorhel <git@yorhel.nl>2021-08-16 16:07:51 +0200
commit376aad0d350657d959a3ac1713a4a86b20ae30d1 (patch)
tree129d94a107ce04c8c91f631e0316e68bc1f943d1
parentf982af81b0a8c5f029ff07580ffde0ae4845aa1c (diff)
Add dark-bg color scheme + enable colors by default if !NO_COLOR
The dark-bg scheme draws an explicit black background, so should also be readable in terminals with a light background. That's been the main show-stopper for enabling colors by default, as the 'dark' color scheme is totally unreadable on light backgrounds and there's no way to detect what background the terminal is actually using.
-rw-r--r--doc/ncdu.pod9
-rw-r--r--src/main.c5
-rw-r--r--src/util.c14
-rw-r--r--src/util.h33
4 files changed, 36 insertions, 25 deletions
diff --git a/doc/ncdu.pod b/doc/ncdu.pod
index 2fcc981..c300f30 100644
--- a/doc/ncdu.pod
+++ b/doc/ncdu.pod
@@ -136,9 +136,12 @@ accidentally press 'q' during or after a very long scan.
=item --color I<SCHEME>
-Select a color scheme. Currently only two schemes are recognized: I<off> to
-disable colors (the default) and I<dark> for a color scheme intended for dark
-backgrounds.
+Select a color scheme. The following schemes are recognized: I<off> to disable
+colors, I<dark> for a color scheme intended for dark backgrounds and I<dark-bg>
+for a variation of the I<dark> color scheme that also works in terminals with a
+light background.
+
+The default is I<dark-bg> unless the C<NO_COLOR> environment variable is set.
=back
diff --git a/src/main.c b/src/main.c
index c72a208..9f1d798 100644
--- a/src/main.c
+++ b/src/main.c
@@ -122,6 +122,8 @@ static void argv_parse(int argc, char **argv) {
char *import = NULL;
char *dir = NULL;
+ uic_theme = getenv("NO_COLOR") ? 0 : 2;
+
static yopt_opt_t opts[] = {
{ 'h', 0, "-h,-?,--help" },
{ 'q', 0, "-q" },
@@ -177,7 +179,7 @@ static void argv_parse(int argc, char **argv) {
printf(" --exclude-firmlinks Exclude firmlinks on macOS\n");
#endif
printf(" --confirm-quit Confirm quitting ncdu\n");
- printf(" --color SCHEME Set color scheme (off/dark)\n");
+ printf(" --color SCHEME Set color scheme (off/dark/dark-bg)\n");
exit(0);
case 'q': update_delay = 2000; break;
case 'v':
@@ -229,6 +231,7 @@ static void argv_parse(int argc, char **argv) {
case 'c':
if(strcmp(val, "off") == 0) { uic_theme = 0; }
else if(strcmp(val, "dark") == 0) { uic_theme = 1; }
+ else if(strcmp(val, "dark-bg") == 0) { uic_theme = 2; }
else {
fprintf(stderr, "Unknown --color option: %s\n", val);
exit(1);
diff --git a/src/util.c b/src/util.c
index 8ea0f49..91c4360 100644
--- a/src/util.c
+++ b/src/util.c
@@ -250,10 +250,16 @@ static const struct {
short fg, bg;
int attr;
} color_defs[] = {
-#define C(name, off_fg, off_bg, off_a, dark_fg, dark_bg, dark_a) \
- {off_fg, off_bg, off_a}, \
- {dark_fg, dark_bg, dark_a},
+#define COLOR__ -1
+#define B A_BOLD
+#define R A_REVERSE
+#define C(name, off_fg, off_bg, off_a, dark_fg, dark_bg, dark_a, darkbg_fg, darkbg_bg, darkbg_a) \
+ {COLOR_##off_fg, COLOR_##off_bg, off_a}, \
+ {COLOR_##dark_fg, COLOR_##dark_bg, dark_a}, \
+ {COLOR_##darkbg_fg, COLOR_##darkbg_bg, darkbg_a},
UI_COLORS
+#undef B
+#undef R
#undef C
{0,0,0}
};
@@ -264,7 +270,7 @@ void uic_init() {
start_color();
use_default_colors();
for(i=0; i<sizeof(colors)/sizeof(*colors)-1; i++) {
- j = i*2 + uic_theme;
+ j = i*3 + uic_theme;
init_pair(i+1, color_defs[j].fg, color_defs[j].bg);
colors[i] = color_defs[j].attr | COLOR_PAIR(i+1);
}
diff --git a/src/util.h b/src/util.h
index 98b2ee3..0eceb36 100644
--- a/src/util.h
+++ b/src/util.h
@@ -31,24 +31,23 @@
/* UI colors: (foreground, background, attrs)
- * NAME OFF DARK
- */
+ * NAME OFF DARK DARK-BG */
#define UI_COLORS \
- C(DEFAULT, -1,-1,0 , -1, -1, 0 )\
- C(BOX_TITLE, -1,-1,A_BOLD , COLOR_BLUE, -1, A_BOLD)\
- C(HD, -1,-1,A_REVERSE , COLOR_BLACK, COLOR_CYAN, 0 ) /* header & footer */\
- C(SEL, -1,-1,A_REVERSE , COLOR_WHITE, COLOR_GREEN,A_BOLD)\
- C(NUM, -1,-1,0 , COLOR_YELLOW, -1, A_BOLD)\
- C(NUM_HD, -1,-1,A_REVERSE , COLOR_YELLOW, COLOR_CYAN, A_BOLD)\
- C(NUM_SEL, -1,-1,A_REVERSE , COLOR_YELLOW, COLOR_GREEN,A_BOLD)\
- C(KEY, -1,-1,A_BOLD , COLOR_YELLOW, -1, A_BOLD)\
- C(KEY_HD, -1,-1,A_BOLD|A_REVERSE, COLOR_YELLOW, COLOR_CYAN, A_BOLD)\
- C(DIR, -1,-1,0 , COLOR_BLUE, -1, A_BOLD)\
- C(DIR_SEL, -1,-1,A_REVERSE , COLOR_BLUE, COLOR_GREEN,A_BOLD)\
- C(FLAG, -1,-1,0 , COLOR_RED, -1, 0 )\
- C(FLAG_SEL, -1,-1,A_REVERSE , COLOR_RED, COLOR_GREEN,0 )\
- C(GRAPH, -1,-1,0 , COLOR_MAGENTA,-1, 0 )\
- C(GRAPH_SEL, -1,-1,A_REVERSE , COLOR_MAGENTA,COLOR_GREEN,0 )
+ C(DEFAULT, _,_,0 , _, _, 0, WHITE, BLACK,0)\
+ C(BOX_TITLE, _,_,B , BLUE, _, B, BLUE, BLACK,B)\
+ C(HD, _,_,R , BLACK, CYAN, 0, BLACK, CYAN, 0) /* header & footer */\
+ C(SEL, _,_,R , WHITE, GREEN,B, WHITE, GREEN,B)\
+ C(NUM, _,_,0 , YELLOW, _, B, YELLOW, BLACK,B)\
+ C(NUM_HD, _,_,R , YELLOW, CYAN, B, YELLOW, CYAN, B)\
+ C(NUM_SEL, _,_,R , YELLOW, GREEN,B, YELLOW, GREEN,B)\
+ C(KEY, _,_,B , YELLOW, _, B, YELLOW, BLACK,B)\
+ C(KEY_HD, _,_,B|R, YELLOW, CYAN, B, YELLOW, CYAN, B)\
+ C(DIR, _,_,0 , BLUE, _, B, BLUE, BLACK,B)\
+ C(DIR_SEL, _,_,R , BLUE, GREEN,B, BLUE, GREEN,B)\
+ C(FLAG, _,_,0 , RED, _, 0, RED, BLACK,0)\
+ C(FLAG_SEL, _,_,R , RED, GREEN,0, RED, GREEN,0)\
+ C(GRAPH, _,_,0 , MAGENTA,_, 0, MAGENTA,BLACK,0)\
+ C(GRAPH_SEL, _,_,R , MAGENTA,GREEN,0, MAGENTA,GREEN,0)
enum ui_coltype {
#define C(name, ...) UIC_##name,