Skip to content
Snippets Groups Projects
Commit 376aad0d authored by Yorhel's avatar Yorhel
Browse files

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.
parent f982af81
No related branches found
No related tags found
No related merge requests found
...@@ -136,9 +136,12 @@ accidentally press 'q' during or after a very long scan. ...@@ -136,9 +136,12 @@ accidentally press 'q' during or after a very long scan.
=item --color I<SCHEME> =item --color I<SCHEME>
Select a color scheme. Currently only two schemes are recognized: I<off> to Select a color scheme. The following schemes are recognized: I<off> to disable
disable colors (the default) and I<dark> for a color scheme intended for dark colors, I<dark> for a color scheme intended for dark backgrounds and I<dark-bg>
backgrounds. 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 =back
......
...@@ -122,6 +122,8 @@ static void argv_parse(int argc, char **argv) { ...@@ -122,6 +122,8 @@ static void argv_parse(int argc, char **argv) {
char *import = NULL; char *import = NULL;
char *dir = NULL; char *dir = NULL;
uic_theme = getenv("NO_COLOR") ? 0 : 2;
static yopt_opt_t opts[] = { static yopt_opt_t opts[] = {
{ 'h', 0, "-h,-?,--help" }, { 'h', 0, "-h,-?,--help" },
{ 'q', 0, "-q" }, { 'q', 0, "-q" },
...@@ -177,7 +179,7 @@ static void argv_parse(int argc, char **argv) { ...@@ -177,7 +179,7 @@ static void argv_parse(int argc, char **argv) {
printf(" --exclude-firmlinks Exclude firmlinks on macOS\n"); printf(" --exclude-firmlinks Exclude firmlinks on macOS\n");
#endif #endif
printf(" --confirm-quit Confirm quitting ncdu\n"); 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); exit(0);
case 'q': update_delay = 2000; break; case 'q': update_delay = 2000; break;
case 'v': case 'v':
...@@ -229,6 +231,7 @@ static void argv_parse(int argc, char **argv) { ...@@ -229,6 +231,7 @@ static void argv_parse(int argc, char **argv) {
case 'c': case 'c':
if(strcmp(val, "off") == 0) { uic_theme = 0; } if(strcmp(val, "off") == 0) { uic_theme = 0; }
else if(strcmp(val, "dark") == 0) { uic_theme = 1; } else if(strcmp(val, "dark") == 0) { uic_theme = 1; }
else if(strcmp(val, "dark-bg") == 0) { uic_theme = 2; }
else { else {
fprintf(stderr, "Unknown --color option: %s\n", val); fprintf(stderr, "Unknown --color option: %s\n", val);
exit(1); exit(1);
......
...@@ -250,10 +250,16 @@ static const struct { ...@@ -250,10 +250,16 @@ static const struct {
short fg, bg; short fg, bg;
int attr; int attr;
} color_defs[] = { } color_defs[] = {
#define C(name, off_fg, off_bg, off_a, dark_fg, dark_bg, dark_a) \ #define COLOR__ -1
{off_fg, off_bg, off_a}, \ #define B A_BOLD
{dark_fg, dark_bg, dark_a}, #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 UI_COLORS
#undef B
#undef R
#undef C #undef C
{0,0,0} {0,0,0}
}; };
...@@ -264,7 +270,7 @@ void uic_init() { ...@@ -264,7 +270,7 @@ void uic_init() {
start_color(); start_color();
use_default_colors(); use_default_colors();
for(i=0; i<sizeof(colors)/sizeof(*colors)-1; i++) { 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); init_pair(i+1, color_defs[j].fg, color_defs[j].bg);
colors[i] = color_defs[j].attr | COLOR_PAIR(i+1); colors[i] = color_defs[j].attr | COLOR_PAIR(i+1);
} }
......
...@@ -31,24 +31,23 @@ ...@@ -31,24 +31,23 @@
/* UI colors: (foreground, background, attrs) /* UI colors: (foreground, background, attrs)
* NAME OFF DARK * NAME OFF DARK DARK-BG */
*/
#define UI_COLORS \ #define UI_COLORS \
C(DEFAULT, -1,-1,0 , -1, -1, 0 )\ C(DEFAULT, _,_,0 , _, _, 0, WHITE, BLACK,0)\
C(BOX_TITLE, -1,-1,A_BOLD , COLOR_BLUE, -1, A_BOLD)\ C(BOX_TITLE, _,_,B , BLUE, _, B, BLUE, BLACK,B)\
C(HD, -1,-1,A_REVERSE , COLOR_BLACK, COLOR_CYAN, 0 ) /* header & footer */\ C(HD, _,_,R , BLACK, CYAN, 0, BLACK, CYAN, 0) /* header & footer */\
C(SEL, -1,-1,A_REVERSE , COLOR_WHITE, COLOR_GREEN,A_BOLD)\ C(SEL, _,_,R , WHITE, GREEN,B, WHITE, GREEN,B)\
C(NUM, -1,-1,0 , COLOR_YELLOW, -1, A_BOLD)\ C(NUM, _,_,0 , YELLOW, _, B, YELLOW, BLACK,B)\
C(NUM_HD, -1,-1,A_REVERSE , COLOR_YELLOW, COLOR_CYAN, A_BOLD)\ C(NUM_HD, _,_,R , YELLOW, CYAN, B, YELLOW, CYAN, B)\
C(NUM_SEL, -1,-1,A_REVERSE , COLOR_YELLOW, COLOR_GREEN,A_BOLD)\ C(NUM_SEL, _,_,R , YELLOW, GREEN,B, YELLOW, GREEN,B)\
C(KEY, -1,-1,A_BOLD , COLOR_YELLOW, -1, A_BOLD)\ C(KEY, _,_,B , YELLOW, _, B, YELLOW, BLACK,B)\
C(KEY_HD, -1,-1,A_BOLD|A_REVERSE, COLOR_YELLOW, COLOR_CYAN, A_BOLD)\ C(KEY_HD, _,_,B|R, YELLOW, CYAN, B, YELLOW, CYAN, B)\
C(DIR, -1,-1,0 , COLOR_BLUE, -1, A_BOLD)\ C(DIR, _,_,0 , BLUE, _, B, BLUE, BLACK,B)\
C(DIR_SEL, -1,-1,A_REVERSE , COLOR_BLUE, COLOR_GREEN,A_BOLD)\ C(DIR_SEL, _,_,R , BLUE, GREEN,B, BLUE, GREEN,B)\
C(FLAG, -1,-1,0 , COLOR_RED, -1, 0 )\ C(FLAG, _,_,0 , RED, _, 0, RED, BLACK,0)\
C(FLAG_SEL, -1,-1,A_REVERSE , COLOR_RED, COLOR_GREEN,0 )\ C(FLAG_SEL, _,_,R , RED, GREEN,0, RED, GREEN,0)\
C(GRAPH, -1,-1,0 , COLOR_MAGENTA,-1, 0 )\ C(GRAPH, _,_,0 , MAGENTA,_, 0, MAGENTA,BLACK,0)\
C(GRAPH_SEL, -1,-1,A_REVERSE , COLOR_MAGENTA,COLOR_GREEN,0 ) C(GRAPH_SEL, _,_,R , MAGENTA,GREEN,0, MAGENTA,GREEN,0)
enum ui_coltype { enum ui_coltype {
#define C(name, ...) UIC_##name, #define C(name, ...) UIC_##name,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment