Browse Source

Show directories in color (default: enabled)

master
Arun Prakash Jana 7 years ago
parent
commit
e780360e7d
No known key found for this signature in database GPG Key ID: A75979F35C080412
3 changed files with 32 additions and 3 deletions
  1. +2
    -0
      README.md
  2. +3
    -0
      nnn.1
  3. +27
    -3
      nnn.c

+ 2
- 0
README.md View File

@@ -67,6 +67,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
- Jump HOME or to the last visited directory (as usual!) - Jump HOME or to the last visited directory (as usual!)
- Jump to initial dir, chdir prompt, cd ..... (with . as PWD) - Jump to initial dir, chdir prompt, cd ..... (with . as PWD)
- Roll-over at edges, page through entries - Roll-over at edges, page through entries
- Show directories in blue (default: enabled)
- Disk usage analyzer mode - Disk usage analyzer mode
- Search - Search
- Filter directory contents with *search-as-you-type* - Filter directory contents with *search-as-you-type*
@@ -141,6 +142,7 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
optional arguments: optional arguments:
-l start in light mode (fewer details) -l start in light mode (fewer details)
-i start in navigate-as-you-type mode -i start in navigate-as-you-type mode
-n disable color for directory entries
-p path to custom nlay -p path to custom nlay
-S start in disk usage analyzer mode -S start in disk usage analyzer mode
-v show program version and exit -v show program version and exit


+ 3
- 0
nnn.1 View File

@@ -107,6 +107,9 @@ supports the following options:
.Fl i .Fl i
start in navigate-as-you-type mode start in navigate-as-you-type mode
.Pp .Pp
.Fl n
disable color for directory entries
.Pp
.Fl "p custom_nlay" .Fl "p custom_nlay"
path to custom nlay path to custom nlay
.Pp .Pp


+ 27
- 3
nnn.c View File

@@ -144,7 +144,8 @@ typedef struct
uchar blkorder : 1; /* Set to sort by blocks used (disk usage) */ uchar blkorder : 1; /* Set to sort by blocks used (disk usage) */
uchar showhidden : 1; /* Set to show hidden files */ uchar showhidden : 1; /* Set to show hidden files */
uchar showdetail : 1; /* Clear to show fewer file info */ uchar showdetail : 1; /* Clear to show fewer file info */
uchar reserved : 2;
uchar showcolor : 1; /* Set to show dirs in blue */
uchar dircolor : 1; /* Current status of dir color */
} settings; } settings;


/* Externs */ /* Externs */
@@ -157,7 +158,8 @@ extern void add_history(const char *string);
extern int wget_wch(WINDOW *win, wint_t *wch); extern int wget_wch(WINDOW *win, wint_t *wch);


/* Globals */ /* Globals */
static settings cfg = {0, 0, 0, 0, 0, 1, 0};
/* Configuration */
static settings cfg = {0, 0, 0, 0, 0, 1, 1, 0};


/* Idle timeout in seconds, 0 to disable */ /* Idle timeout in seconds, 0 to disable */
static int idletimeout; static int idletimeout;
@@ -380,6 +382,7 @@ initcurses(void)
curs_set(FALSE); /* Hide cursor */ curs_set(FALSE); /* Hide cursor */
start_color(); start_color();
use_default_colors(); use_default_colors();
init_pair(1, COLOR_BLUE, -1);
timeout(1000); /* One second */ timeout(1000); /* One second */
} }


@@ -991,6 +994,12 @@ printent(struct entry *ent, int sel)
snprintf(g_buf, ncols, "%s%s", CURSYM(sel), snprintf(g_buf, ncols, "%s%s", CURSYM(sel),
replace_escape(ent->name)); replace_escape(ent->name));


/* Dirs are always shown on top */
if (cfg.dircolor && !S_ISDIR(ent->mode)) {
attroff(COLOR_PAIR(1));
cfg.dircolor = 0;
}

printw("%s\n", g_buf); printw("%s\n", g_buf);
} }


@@ -1096,6 +1105,12 @@ printent_long(struct entry *ent, int sel)
replace_escape(ent->name)); replace_escape(ent->name));
} }


/* Dirs are always shown on top */
if (cfg.dircolor && !S_ISDIR(ent->mode)) {
attroff(COLOR_PAIR(1));
cfg.dircolor = 0;
}

printw("%s\n", g_buf); printw("%s\n", g_buf);


if (sel) if (sel)
@@ -1675,6 +1690,11 @@ redraw(char *path)
g_buf[ncols - strlen(CWD) - 1] = '\0'; g_buf[ncols - strlen(CWD) - 1] = '\0';
printw(CWD "%s\n\n", g_buf); printw(CWD "%s\n\n", g_buf);


if (cfg.showcolor) {
attron(COLOR_PAIR(1));
cfg.dircolor = 1;
}

/* Print listing */ /* Print listing */
if (cur < (nlines >> 1)) { if (cur < (nlines >> 1)) {
for (i = 0; i < nlines; ++i) for (i = 0; i < nlines; ++i)
@@ -2353,6 +2373,7 @@ positional arguments:\n\
optional arguments:\n\ optional arguments:\n\
-l start in light mode (fewer details)\n\ -l start in light mode (fewer details)\n\
-i start in navigate-as-you-type mode\n\ -i start in navigate-as-you-type mode\n\
-n disable color for directory entries\n\
-p path to custom nlay\n\ -p path to custom nlay\n\
-S start in disk usage analyzer mode\n\ -S start in disk usage analyzer mode\n\
-v show program version and exit\n\ -v show program version and exit\n\
@@ -2377,7 +2398,7 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }


while ((opt = getopt(argc, argv, "dlSip:vh")) != -1) {
while ((opt = getopt(argc, argv, "dlSinp:vh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
cfg.blkorder = 1; cfg.blkorder = 1;
@@ -2389,6 +2410,9 @@ main(int argc, char *argv[])
case 'i': case 'i':
cfg.filtermode = 1; cfg.filtermode = 1;
break; break;
case 'n':
cfg.showcolor = 0;
break;
case 'p': case 'p':
player = optarg; player = optarg;
break; break;


Loading…
Cancel
Save