diff --git a/doc/ncdu.pod b/doc/ncdu.pod index 861271a4c06f27e9aad1d4ccca68664c1943013d..6486416ca5c97f55f569eeac7199369cbadb5873 100644 --- a/doc/ncdu.pod +++ b/doc/ncdu.pod @@ -118,6 +118,12 @@ prefixes, that is, powers of 1024 (KiB, MiB, etc). Requires a confirmation before quitting ncdu. Very helpful when you 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. + =back =head2 Scan Options diff --git a/src/browser.c b/src/browser.c index a7ab4240327d3becb0abd09f4b3bcff69d3acf66..0ed690e41234b70e19074e13a5045039564e054f 100644 --- a/src/browser.c +++ b/src/browser.c @@ -64,13 +64,13 @@ static void browse_draw_info(struct dir *dr) { ncmove(6, 18); printsize(UIC_DEFAULT, dr->size); addstrc(UIC_DEFAULT, " ("); - addstrc(UIC_KEYNUM, fullsize(dr->size)); + addstrc(UIC_NUM, fullsize(dr->size)); addstrc(UIC_DEFAULT, " B)"); ncmove(7, 18); printsize(UIC_DEFAULT, dr->asize); addstrc(UIC_DEFAULT, " ("); - addstrc(UIC_KEYNUM, fullsize(dr->asize)); + addstrc(UIC_NUM, fullsize(dr->asize)); addstrc(UIC_DEFAULT, " B)"); break; @@ -88,7 +88,7 @@ static void browse_draw_info(struct dir *dr) { } ncaddstr(9, 31, "Press "); - addchc(UIC_KEYNUM, 'i'); + addchc(UIC_KEY, 'i'); addstrc(UIC_DEFAULT, " to hide this window"); } @@ -129,7 +129,7 @@ static void browse_draw_graph(struct dir *n, int *x) { pc = (float)(show_as ? n->parent->asize : n->parent->size); if(pc < 1) pc = 1.0f; - uic_set(c == UIC_SEL ? UIC_KEYNUM_SEL : UIC_KEYNUM); + uic_set(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM); printw("%5.1f", ((float)(show_as ? n->asize : n->size) / pc) * 100.0f); addchc(c, '%'); } @@ -158,10 +158,10 @@ static void browse_draw_items(struct dir *n, int *x) { if(n->items > 99999) { addstrc(c, "> "); - addstrc(c == UIC_SEL ? UIC_KEYNUM_SEL : UIC_KEYNUM, "100"); + addstrc(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM, "100"); addchc(c, 'k'); } else if(n->items) { - uic_set(c == UIC_SEL ? UIC_KEYNUM_SEL : UIC_KEYNUM); + uic_set(c == UIC_SEL ? UIC_NUM_SEL : UIC_NUM); printw("%6s", fullsize(n->items)); } } @@ -189,7 +189,9 @@ static void browse_draw_item(struct dir *n, int row) { browse_draw_items(n, &x); move(row, x); - addchc(c == UIC_SEL ? UIC_DIR_SEL : UIC_DIR, n->flags & FF_DIR ? '/' : ' '); + if(n->flags & FF_DIR) + c = c == UIC_SEL ? UIC_DIR_SEL : UIC_DIR; + addchc(c, n->flags & FF_DIR ? '/' : ' '); addstrc(c, cropstr(n->name, wincols-x-1)); } @@ -206,7 +208,7 @@ void browse_draw() { uic_set(UIC_HD); mvhline(0, 0, ' ', wincols); mvprintw(0,0,"%s %s ~ Use the arrow keys to navigate, press ", PACKAGE_NAME, PACKAGE_VERSION); - addchc(UIC_KEYNUM_HD, '?'); + addchc(UIC_KEY_HD, '?'); addstrc(UIC_HD, " for help"); if(dir_import_active) mvaddstr(0, wincols-10, "[imported]"); @@ -229,10 +231,10 @@ void browse_draw() { mvaddstr(winrows-1, 0, " Total disk usage: "); printsize(UIC_HD, t->parent->size); addstrc(UIC_HD, " Apparent size: "); - uic_set(UIC_KEYNUM_HD); + uic_set(UIC_NUM_HD); printsize(UIC_HD, t->parent->asize); addstrc(UIC_HD, " Items: "); - uic_set(UIC_KEYNUM_HD); + uic_set(UIC_NUM_HD); printw("%d", t->parent->items); } else mvaddstr(winrows-1, 0, " No items to display."); diff --git a/src/delete.c b/src/delete.c index 8e97992d5e36799eba892b5c72098d890081f54a..336b5043a8abefd5287285618f45ab67aa38e03a 100644 --- a/src/delete.c +++ b/src/delete.c @@ -71,7 +71,7 @@ static void delete_draw_progress() { ncaddstr(1, 2, cropstr(getpath(curdir), 47)); ncaddstr(4, 41, "Press "); - addchc(UIC_KEYNUM, 'q'); + addchc(UIC_KEY, 'q'); addstrc(UIC_DEFAULT, " to abort"); } diff --git a/src/dir_common.c b/src/dir_common.c index 3d733b42c7cebb185fa0e6b49e56d9c9e289c016..95f26add541427190903ace4e3b6e0ac013ddce9 100644 --- a/src/dir_common.c +++ b/src/dir_common.c @@ -132,7 +132,7 @@ static void draw_progress() { nccreate(10, width, antext); ncaddstr(2, 2, "Total items: "); - uic_set(UIC_KEYNUM); + uic_set(UIC_NUM); printw("%-8d", dir_output.items); if(dir_output.size) { @@ -144,11 +144,11 @@ static void draw_progress() { ncprint(3, 2, "Current item: %s", cropstr(dir_curpath, width-18)); if(confirm_quit_while_scanning_stage_1_passed) { ncaddstr(8, width-26, "Press "); - addchc(UIC_KEYNUM, 'y'); + addchc(UIC_KEY, 'y'); addstrc(UIC_DEFAULT, " to confirm abort"); } else { ncaddstr(8, width-18, "Press "); - addchc(UIC_KEYNUM, 'q'); + addchc(UIC_KEY, 'q'); addstrc(UIC_DEFAULT, " to abort"); } diff --git a/src/help.c b/src/help.c index 5341cd960c0fd0ab254ec7f3b558618f819ce764..28762742fb5ff01634c163e74d626b912470f9ea 100644 --- a/src/help.c +++ b/src/help.c @@ -62,7 +62,7 @@ void help_draw() { nccreate(15, 60, "ncdu help"); ncaddstr(13, 42, "Press "); - uic_set(UIC_KEYNUM); + uic_set(UIC_KEY); addch('q'); uic_set(UIC_DEFAULT); addstr(" to close"); @@ -75,7 +75,7 @@ void help_draw() { case 1: line = 1; for(i=start*2; i<start*2+20; i+=2) { - uic_set(UIC_KEYNUM); + uic_set(UIC_KEY); ncaddstr(++line, 13-strlen(keys[i]), keys[i]); uic_set(UIC_DEFAULT); ncaddstr(line, 15, keys[i+1]); diff --git a/src/main.c b/src/main.c index b79c66361719f8fa0bf5ebfb30f546ab62960728..15d8545b57a4e8e4fc27fe9b40cb960e40b6ce3a 100644 --- a/src/main.c +++ b/src/main.c @@ -131,6 +131,7 @@ static void argv_parse(int argc, char **argv) { { 'C', 0, "--exclude-caches" }, { 's', 0, "--si" }, { 'Q', 0, "--confirm-quit" }, + { 'c', 1, "--color" }, {0,0,NULL} }; @@ -180,6 +181,14 @@ static void argv_parse(int argc, char **argv) { case 'C': cachedir_tags = 1; break; + case 'c': + if(strcmp(val, "off") == 0) { uic_theme = 0; } + if(strcmp(val, "dark") == 0) { uic_theme = 1; } + else { + fprintf(stderr, "Unknown --color option: %s\n", val); + exit(1); + } + break; case -2: fprintf(stderr, "ncdu: %s.\n", val); exit(1); diff --git a/src/util.c b/src/util.c index f931b41b590011252cab9dff7096138a54f5f58c..11be394b5950de50dea5336e8730f9fcdbf268b8 100644 --- a/src/util.c +++ b/src/util.c @@ -33,6 +33,7 @@ #include <locale.h> #endif +int uic_theme; int winrows, wincols; int subwinr, subwinc; int si; @@ -87,7 +88,7 @@ float formatsize(int64_t from, char **unit) { void printsize(enum ui_coltype t, int64_t from) { char *unit; float r = formatsize(from, &unit); - uic_set(t == UIC_HD ? UIC_KEYNUM_HD : t == UIC_SEL ? UIC_KEYNUM_SEL : UIC_KEYNUM); + uic_set(t == UIC_HD ? UIC_NUM_HD : t == UIC_SEL ? UIC_NUM_SEL : UIC_NUM); printw("%5.1f", r); addchc(t, ' '); addstrc(t, unit); @@ -201,7 +202,7 @@ void ncprint(int r, int c, char *fmt, ...) { void nctab(int c, int sel, int num, char *str) { - uic_set(sel ? UIC_KEYNUM_HD : UIC_KEYNUM); + uic_set(sel ? UIC_KEY_HD : UIC_KEY); ncprint(0, c, "%d", num); uic_set(sel ? UIC_HD : UIC_DEFAULT); addch(':'); @@ -211,24 +212,36 @@ void nctab(int c, int sel, int num, char *str) { static int colors[] = { -#define C(name, fg, bg, attr) 0, +#define C(name, ...) 0, UI_COLORS #undef C 0 }; static int lastcolor = 0; -void uic_init() { - start_color(); - use_default_colors(); - int i=0; -#define C(name, fg, bg, attr) \ - init_pair(i+1, fg, bg);\ - colors[i] = attr | COLOR_PAIR(i+1);\ - i++; +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}, UI_COLORS #undef C + {0,0,0} +}; + +void uic_init() { + size_t i, j; + + start_color(); + use_default_colors(); + for(i=0; i<sizeof(colors)/sizeof(*colors)-1; i++) { + j = i*2 + uic_theme; + init_pair(i+1, color_defs[j].fg, color_defs[j].bg); + colors[i] = color_defs[j].attr | COLOR_PAIR(i+1); + } } void uic_set(enum ui_coltype c) { diff --git a/src/util.h b/src/util.h index bb9e16bbdf81332331f53991b493e37026af57cd..525a9c11c95b7a788ecac368c25af0bc67f5d3a4 100644 --- a/src/util.h +++ b/src/util.h @@ -30,30 +30,36 @@ #include <ncurses.h> -/* UI colors: C(name, foreground, background, attrs) */ +/* UI colors: (foreground, background, attrs) + * NAME OFF DARK + */ #define UI_COLORS \ - C(DEFAULT, -1, -1, 0 )\ - C(BOX_TITLE, COLOR_BLUE, -1, A_BOLD)\ - C(HD, COLOR_BLACK, COLOR_CYAN, 0 ) /* header & footer */\ - C(SEL, COLOR_WHITE, COLOR_GREEN, A_BOLD)\ - C(KEYNUM, COLOR_YELLOW, -1, A_BOLD)\ - C(KEYNUM_HD, COLOR_YELLOW, COLOR_CYAN, A_BOLD)\ - C(KEYNUM_SEL, COLOR_YELLOW, COLOR_GREEN, A_BOLD)\ - C(DIR, COLOR_BLUE, -1, A_BOLD)\ - C(DIR_SEL, COLOR_BLUE, COLOR_GREEN, A_BOLD)\ - C(FLAG, COLOR_RED, -1, 0 )\ - C(FLAG_SEL, COLOR_RED, COLOR_GREEN, 0 )\ - C(GRAPH, COLOR_MAGENTA, -1, 0 )\ - C(GRAPH_SEL, COLOR_MAGENTA, COLOR_GREEN, 0 ) + 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 ) enum ui_coltype { -#define C(name, fg, bg, attr) UIC_##name, +#define C(name, ...) UIC_##name, UI_COLORS #undef C UIC_NONE }; /* Color & attribute manipulation */ +extern int uic_theme; + void uic_init(); void uic_set(enum ui_coltype);