diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-08-04 20:36:19 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-08-04 20:36:19 +0530 |
commit | 42fd2a4d13c370e54ebe812560fc7e82c17ccc97 (patch) | |
tree | 0233dc8273638859e274359b465d60071ffa75da | |
parent | ae961da157597e2fc8df27bf38728c0630fe567e (diff) | |
download | nnn-42fd2a4d13c370e54ebe812560fc7e82c17ccc97.tar.gz |
Program option to use older
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | misc/auto-completion/bash/nnn-completion.bash | 1 | ||||
-rw-r--r-- | misc/auto-completion/fish/nnn.fish | 3 | ||||
-rw-r--r-- | misc/auto-completion/zsh/_nnn | 3 | ||||
-rw-r--r-- | nnn.1 | 6 | ||||
-rw-r--r-- | src/nnn.c | 121 |
6 files changed, 63 insertions, 75 deletions
@@ -61,10 +61,6 @@ ifeq ($(O_NOFIFO),1) CPPFLAGS += -DNOFIFO endif -ifeq ($(O_NOFCOLORS),1) - CPPFLAGS += -DNOFCOLORS -endif - ifeq ($(O_CTX8),1) CPPFLAGS += -DCTX8 endif diff --git a/misc/auto-completion/bash/nnn-completion.bash b/misc/auto-completion/bash/nnn-completion.bash index 63ad1d7..dfadb53 100644 --- a/misc/auto-completion/bash/nnn-completion.bash +++ b/misc/auto-completion/bash/nnn-completion.bash @@ -39,6 +39,7 @@ _nnn () -T -u -V + -w -x -h ) diff --git a/misc/auto-completion/fish/nnn.fish b/misc/auto-completion/fish/nnn.fish index 655d56c..77e6bad 100644 --- a/misc/auto-completion/fish/nnn.fish +++ b/misc/auto-completion/fish/nnn.fish @@ -15,7 +15,7 @@ complete -c nnn -s a -d 'auto-create NNN_FIFO' complete -c nnn -s A -d 'disable dir auto-select' complete -c nnn -s b -r -d 'bookmark key to open' -x -a '(echo $NNN_BMS | awk -F: -v RS=\; \'{print $1"\t"$2}\')' complete -c nnn -s c -d 'cli-only opener' -complete -c nnn -s C -d 'hardware cursor mode' +complete -c nnn -s C -d 'color by context' complete -c nnn -s d -d 'start in detail mode' complete -c nnn -s e -d 'open text files in $VISUAL/$EDITOR/vi' complete -c nnn -s E -d 'use EDITOR for undetached edits' @@ -38,5 +38,6 @@ complete -c nnn -s t -r -d 'timeout in seconds to lock' complete -c nnn -s T -r -d 'a d e r s t v' complete -c nnn -s u -d 'use selection (no prompt)' complete -c nnn -s V -d 'show program version and exit' +complete -c nnn -s w -d 'hardware cursor mode' complete -c nnn -s x -d 'notis, sel to system clipboard' complete -c nnn -s h -d 'show program help' diff --git a/misc/auto-completion/zsh/_nnn b/misc/auto-completion/zsh/_nnn index 1bc328a..2d973a1 100644 --- a/misc/auto-completion/zsh/_nnn +++ b/misc/auto-completion/zsh/_nnn @@ -13,7 +13,7 @@ args=( '(-A)-A[disable dir auto-select]' '(-b)-b[bookmark key to open]:key char' '(-c)-c[cli-only opener]' - '(-C)-C[hardware cursor mode]' + '(-C)-C[color by context]' '(-d)-d[start in detail mode]' '(-e)-e[open text files in $VISUAL/$EDITOR/vi]' '(-E)-E[use EDITOR for undetached edits]' @@ -36,6 +36,7 @@ args=( '(-T)-T[a d e r s t v]:key' '(-u)-u[use selection (no prompt)]' '(-V)-V[show program version and exit]' + '(-w)-C[hardware cursor mode]' '(-x)-x[notis, sel to system clipboard]' '(-h)-h[show program help]' '*:filename:_files' @@ -17,6 +17,7 @@ .Op Ar -f .Op Ar -F .Op Ar -g +.Op Ar -h .Op Ar -H .Op Ar -K .Op Ar -l @@ -71,7 +72,7 @@ supports the following options: indicates that the opener is a cli-only opener (overrides -e) .Pp .Fl C - place hardware cursor on hovered entry + color directories by context, disable file colors .Pp .Fl d detail mode @@ -91,6 +92,9 @@ supports the following options: .Fl g use regex filters instead of substring match .Pp +.Fl h + place hardware cursor on hovered entry +.Pp .Fl H show hidden files .Pp @@ -304,7 +304,8 @@ typedef struct { uint runplugin : 1; /* Choose plugin mode */ uint runctx : 2; /* The context in which plugin is to be run */ uint selmode : 1; /* Set when selecting files */ - uint reserved : 15; + uint ctxcolor : 1; /* Show dirs in context colors */ + uint reserved : 14; } runstate; /* Contexts or workspaces */ @@ -682,10 +683,8 @@ static const char * const patterns[] = { #define C_SOC (C_PIP + 1) /* Socket: MediumOrchid1 */ #define C_UND (C_SOC + 1) /* Unknown OR 0B regular/exe file: Red1 */ -#ifndef NOFCOLORS static char gcolors[] = "c1e2272e006033f9c6d6abc4"; static uint fcolors[C_UND + 1] = {0}; -#endif /* Event handling */ #ifdef LINUX_INOTIFY @@ -1569,27 +1568,26 @@ static void export_file_list(void) unlink(g_tmpfpath); } -#ifndef NOFCOLORS static bool init_fcolors(void) { char *f_colors = getenv("NNN_FCOLORS"); - if (f_colors) { - for (uchar id = C_BLK; *f_colors && id <= C_UND; ++id) { - fcolors[id] = xchartohex(*f_colors) << 4; - if (*++f_colors) { - fcolors[id] += xchartohex(*f_colors); - if (fcolors[id]) - init_pair(id, fcolors[id], -1); - } else - return FALSE; - ++f_colors; - } + if (!f_colors || !*f_colors) + f_colors = gcolors; + + for (uchar id = C_BLK; *f_colors && id <= C_UND; ++id) { + fcolors[id] = xchartohex(*f_colors) << 4; + if (*++f_colors) { + fcolors[id] += xchartohex(*f_colors); + if (fcolors[id]) + init_pair(id, fcolors[id], -1); + } else + return FALSE; + ++f_colors; } return TRUE; } -#endif /* Initialize curses mode */ static bool initcurses(void *oldmask) @@ -1650,13 +1648,11 @@ static bool initcurses(void *oldmask) if (sep) *sep = '\0'; -#ifndef NOFCOLORS - if (!init_fcolors()) { + if (!(g_state.ctxcolor || init_fcolors())) { exitcurses(); fprintf(stderr, "NNN_FCOLORS!\n"); return FALSE; } -#endif } else { colors = sep; /* Detect if 8 colors fallback is appended */ if (colors) @@ -3220,7 +3216,6 @@ static char *get_kv_val(kv *kvarr, char *buf, int key, uchar max, uchar id) return NULL; } -#ifdef NOFCOLORS static void resetdircolor(int flags) { if (g_state.dircolor && !(flags & DIR_OR_LINK_TO_DIR)) { @@ -3228,7 +3223,6 @@ static void resetdircolor(int flags) g_state.dircolor = 0; } } -#endif /* * Replace escape characters in a string with '?' @@ -3443,38 +3437,39 @@ static void printent(const struct entry *ent, uint namecols, bool sel) { uchar pair = 0; char ind = get_ind(ent->mode, FALSE, &pair); -#ifdef NOFCOLORS - int attrs = ((ind == '@' || (ent->flags & HARD_LINK)) ? A_DIM : 0) | (sel ? A_REVERSE : 0); -#else int attrs = sel ? A_REVERSE : 0; -#endif - if (ind == '@') { - pair = (ent->flags & SYM_ORPHAN) ? C_ORP : C_LNK; + if (g_state.ctxcolor) { + if (ind == '@') { + if (ent->flags & DIR_OR_LINK_TO_DIR) + ind = '/'; + attrs |= A_DIM; + } else if (ent->flags & HARD_LINK) + attrs |= A_DIM; + } else { + if (ind == '@') { + if (ent->flags & DIR_OR_LINK_TO_DIR) + ind = '/'; + pair = (ent->flags & SYM_ORPHAN) ? C_ORP : C_LNK; + } else if (!ent->size && (pair == C_FIL || pair == C_EXE)) + pair = C_UND; + else if (ent->flags & HARD_LINK) + pair = C_HRD; + else if (ent->flags & FILE_MISSING) + pair = C_MIS; - if (ent->flags & DIR_OR_LINK_TO_DIR) - ind = '/'; - } else if (!ent->size && (pair == C_FIL || pair == C_EXE)) - pair = C_UND; - else if (ent->flags & HARD_LINK) - pair = C_HRD; - else if (ent->flags & FILE_MISSING) - pair = C_MIS; + if (pair && fcolors[pair]) + attrs |= COLOR_PAIR(pair); + } if (!ind) ++namecols; -#ifdef NOFCOLORS /* Directories are always shown on top */ resetdircolor(ent->flags); -#endif addch((ent->flags & FILE_SELECTED) ? '+' : ' '); -#ifndef NOFCOLORS - if (pair && fcolors[pair]) - attrs |= COLOR_PAIR(pair); -#endif if (attrs) attron(attrs); @@ -3484,10 +3479,6 @@ static void printent(const struct entry *ent, uint namecols, bool sel) addstr(unescape(ent->name, MIN(namecols, ent->nlen) + 1)); #endif -#ifndef NOFCOLORS - if (pair && fcolors[pair]) - attrs |= COLOR_PAIR(pair); -#endif if (attrs) attroff(attrs); @@ -3504,10 +3495,8 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel) uint len; char *size; -#ifdef NOFCOLORS /* Directories are always shown on top */ resetdircolor(ent->flags); -#endif addch((ent->flags & FILE_SELECTED) ? '+' : ' '); @@ -5372,22 +5361,19 @@ static int adjust_cols(int ncols) static void draw_line(char *path, int ncols) { - ncols = adjust_cols(ncols); - -#ifdef NOFCOLORS bool dir = FALSE; - if (pdents[last].flags & DIR_OR_LINK_TO_DIR) { + ncols = adjust_cols(ncols); + + if (g_state.ctxcolor && (pdents[last].flags & DIR_OR_LINK_TO_DIR)) { attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); dir = TRUE; } -#endif move(2 + last - curscroll, 0); printptr(&pdents[last], ncols, false); -#ifdef NOFCOLORS - if (pdents[cur].flags & DIR_OR_LINK_TO_DIR) { + if (g_state.ctxcolor && (pdents[cur].flags & DIR_OR_LINK_TO_DIR)) { if (!dir) {/* First file is not a directory */ attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); dir = TRUE; @@ -5396,16 +5382,13 @@ static void draw_line(char *path, int ncols) attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); dir = FALSE; } -#endif move(2 + cur - curscroll, 0); printptr(&pdents[cur], ncols, true); -#ifdef NOFCOLORS /* Must reset e.g. no files in dir */ if (dir) attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); -#endif statusbar(path); } @@ -5496,22 +5479,20 @@ static void redraw(char *path) ncols = adjust_cols(ncols); -#ifdef NOFCOLORS - attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); - g_state.dircolor = 1; -#endif + if (g_state.ctxcolor) { + attron(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); + g_state.dircolor = 1; + } /* Print listing */ for (i = curscroll; i < ndents && i < curscroll + onscreen; ++i) printptr(&pdents[i], ncols, i == cur); -#ifdef NOFCOLORS /* Must reset e.g. no files in dir */ if (g_state.dircolor) { attroff(COLOR_PAIR(cfg.curctx + 1) | A_BOLD); g_state.dircolor = 0; } -#endif statusbar(path); } @@ -7053,7 +7034,7 @@ static void usage(void) " -A no dir auto-select\n" " -b key open bookmark key (trumps -s/S)\n" " -c cli-only NNN_OPENER (trumps -e)\n" - " -C place HW cursor on hovered\n" + " -C color by context\n" " -d detail mode\n" " -e text in $VISUAL/$EDITOR/vi\n" " -E use EDITOR for undetached edits\n" @@ -7078,6 +7059,7 @@ static void usage(void) " -T key sort order [a/d/e/r/s/t/v]\n" " -u use selection (no prompt)\n" " -V show version\n" + " -w place HW cursor on hovered\n" " -x notis, sel to system clipboard\n" " -h show help\n\n" "v%s\n%s\n", __func__, VERSION, GENERAL_INFO); @@ -7223,7 +7205,7 @@ int main(int argc, char *argv[]) while ((opt = (env_opts_id > 0 ? env_opts[--env_opts_id] - : getopt(argc, argv, "aAb:cCdeEfFgHKl:nop:P:QrRs:St:T:uVxh"))) != -1) { + : getopt(argc, argv, "aAb:cCdeEfFgHKl:nop:P:QrRs:St:T:uVwxh"))) != -1) { switch (opt) { #ifndef NOFIFO case 'a': @@ -7240,6 +7222,9 @@ int main(int argc, char *argv[]) case 'c': cfg.cliopener = 1; break; + case 'C': + g_state.ctxcolor = 1; + break; case 'd': cfg.showdetail = 1; printptr = &printent_long; @@ -7262,9 +7247,6 @@ int main(int argc, char *argv[]) cfg.regex = 1; filterfn = &visible_re; break; - case 'C': - cfg.cursormode = 1; - break; case 'H': cfg.showhidden = 1; break; @@ -7337,6 +7319,9 @@ int main(int argc, char *argv[]) case 'V': fprintf(stdout, "%s\n", VERSION); return EXIT_SUCCESS; + case 'w': + cfg.cursormode = 1; + break; case 'x': cfg.x11 = 1; break; |