Option -D to show dirs in context color

This commit is contained in:
Arun Prakash Jana 2020-09-01 22:54:43 +05:30
parent a8afbf89d5
commit 02bb398550
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 22 additions and 7 deletions

4
nnn.1
View file

@ -12,6 +12,7 @@
.Op Ar -c .Op Ar -c
.Op Ar -C .Op Ar -C
.Op Ar -d .Op Ar -d
.Op Ar -D
.Op Ar -e .Op Ar -e
.Op Ar -E .Op Ar -E
.Op Ar -f .Op Ar -f
@ -78,6 +79,9 @@ supports the following options:
.Fl d .Fl d
detail mode detail mode
.Pp .Pp
.Fl D
show directories in context color with \fBNNN_FCOLORS\fR set
.Pp
.Fl e .Fl e
open text files in $VISUAL (else $EDITOR, fallback vi) [preferably CLI] open text files in $VISUAL (else $EDITOR, fallback vi) [preferably CLI]
.Pp .Pp

View file

@ -312,9 +312,10 @@ typedef struct {
uint runplugin : 1; /* Choose plugin mode */ uint runplugin : 1; /* Choose plugin mode */
uint runctx : 2; /* The context in which plugin is to be run */ uint runctx : 2; /* The context in which plugin is to be run */
uint selmode : 1; /* Set when selecting files */ uint selmode : 1; /* Set when selecting files */
uint oldcolor : 1; /* Show dirs in context colors */ uint oldcolor : 1; /* Use older colorscheme */
uint reserved : 14;
uint stayonsel : 1; /* Disable auto-proceed on select */ uint stayonsel : 1; /* Disable auto-proceed on select */
uint dirctx : 1; /* Show dirs in context color */
uint reserved : 12;
} runstate; } runstate;
/* Contexts or workspaces */ /* Contexts or workspaces */
@ -1722,7 +1723,7 @@ static bool initcurses(void *oldmask)
if (ext) { if (ext) {
*pcode = xchartohex(*colors) << 4; *pcode = xchartohex(*colors) << 4;
if (*++colors) if (*++colors)
*pcode += xchartohex(*colors); fcolors[i + 1] = *pcode += xchartohex(*colors);
else { /* Each color code must be 2 hex symbols */ else { /* Each color code must be 2 hex symbols */
exitcurses(); exitcurses();
fprintf(stderr, "NNN_COLORS!\n"); fprintf(stderr, "NNN_COLORS!\n");
@ -3569,8 +3570,11 @@ static void printent(const struct entry *ent, uint namecols, bool sel)
break; break;
case S_IFDIR: case S_IFDIR:
pair = C_DIR; pair = C_DIR;
if (!g_state.oldcolor) if (!g_state.oldcolor) {
attrs |= A_BOLD; attrs |= A_BOLD;
if (g_state.dirctx)
pair = cfg.curctx + 1;
}
ind = '/'; ind = '/';
break; break;
case S_IFLNK: case S_IFLNK:
@ -3651,7 +3655,7 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel)
bool ln = FALSE; bool ln = FALSE;
char ind1 = '\0', ind2 = '\0'; char ind1 = '\0', ind2 = '\0';
uchar pair = 0; uchar pair = 0;
int attrs = sel ? A_REVERSE | (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS)) int attrs = sel ? (A_REVERSE | (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS)))
: (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS)); : (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS));
uint len; uint len;
char *size; char *size;
@ -3677,8 +3681,11 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel)
switch (ent->mode & S_IFMT) { switch (ent->mode & S_IFMT) {
case S_IFDIR: case S_IFDIR:
pair = C_DIR; pair = C_DIR;
if (!g_state.oldcolor) if (!g_state.oldcolor) {
attrs |= A_BOLD; attrs |= A_BOLD;
if (g_state.dirctx)
pair = cfg.curctx + 1;
}
ind2 = '/'; // fallthrough ind2 = '/'; // fallthrough
case S_IFREG: case S_IFREG:
if (!ind2) { if (!ind2) {
@ -7249,6 +7256,7 @@ static void usage(void)
" -c cli-only NNN_OPENER (trumps -e)\n" " -c cli-only NNN_OPENER (trumps -e)\n"
" -C earlier colorscheme\n" " -C earlier colorscheme\n"
" -d detail mode\n" " -d detail mode\n"
" -D dirs in context color\n"
" -e text in $VISUAL/$EDITOR/vi\n" " -e text in $VISUAL/$EDITOR/vi\n"
" -E use EDITOR for undetached edits\n" " -E use EDITOR for undetached edits\n"
#ifndef NORL #ifndef NORL
@ -7419,7 +7427,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0 while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id] ? env_opts[--env_opts_id]
: getopt(argc, argv, "aAb:cCdeEfFgHJKl:nop:P:QrRs:St:T:uVwxh"))) != -1) { : getopt(argc, argv, "aAb:cCdDeEfFgHJKl:nop:P:QrRs:St:T:uVwxh"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':
@ -7443,6 +7451,9 @@ int main(int argc, char *argv[])
cfg.showdetail = 1; cfg.showdetail = 1;
printptr = &printent_long; printptr = &printent_long;
break; break;
case 'D':
g_state.dirctx = 1;
break;
case 'e': case 'e':
cfg.useeditor = 1; cfg.useeditor = 1;
break; break;