Skip to content

Commit

Permalink
Option -C to disable color
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Apr 5, 2020
1 parent 0e3146e commit 02c02c5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions misc/auto-completion/bash/nnn-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ _nnn ()
-A
-b
-c
-C
-d
-e
-E
Expand Down
1 change: 1 addition & 0 deletions misc/auto-completion/fish/nnn.fish
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
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 'disable color'
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'
Expand Down
1 change: 1 addition & 0 deletions misc/auto-completion/zsh/_nnn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ args=(
'(-A)-A[disable dir auto-select]'
'(-b)-b[bookmark key to open]:key char'
'(-c)-c[cli-only opener]'
'(-C)-C[disable color]'
'(-d)-d[start in detail mode]'
'(-e)-e[open text files in $VISUAL/$EDITOR/vi]'
'(-E)-E[use EDITOR for undetached edits]'
Expand Down
4 changes: 4 additions & 0 deletions nnn.1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
.Op Ar -A
.Op Ar -b key
.Op Ar -c
.Op Ar -C
.Op Ar -d
.Op Ar -e
.Op Ar -E
Expand Down Expand Up @@ -62,6 +63,9 @@ supports the following options:
.Fl c
opener opens files in cli utilities only (overrides -e)
.Pp
.Fl C
disable color
.Pp
.Fl d
detail mode
.Pp
Expand Down
53 changes: 32 additions & 21 deletions src/nnn.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
#define STATE_TRASH 0x40
#define STATE_FORCEQUIT 0x80
#define STATE_FORTUNE 0x100
#define STATE_NOCOLOR 0x200

static uint g_states;

Expand Down Expand Up @@ -1522,18 +1523,21 @@ static bool initcurses(void *oldmask)
mouseinterval(0);
#endif
curs_set(FALSE); /* Hide cursor */
start_color();
use_default_colors();

/* Get and set the context colors */
for (i = 0; i < CTX_MAX; ++i) {
if (*colors) {
g_ctx[i].color = (*colors < '0' || *colors > '7') ? 4 : *colors - '0';
++colors;
} else
g_ctx[i].color = 4;

init_pair(i + 1, g_ctx[i].color, -1);
if (!(g_states & STATE_NOCOLOR)) {
start_color();
use_default_colors();

/* Get and set the context colors */
for (i = 0; i < CTX_MAX; ++i) {
if (*colors) {
g_ctx[i].color = (*colors < '0' || *colors > '7') ? 4 : *colors - '0';
++colors;
} else
g_ctx[i].color = 4;

init_pair(i + 1, g_ctx[i].color, -1);
}
}

settimeout(); /* One second */
Expand Down Expand Up @@ -3206,7 +3210,7 @@ static char get_ind(mode_t mode, bool perms)
return '*';
return '\0';
case S_IFDIR:
return perms ? 'd' : '\0';
return perms ? 'd' : '/';
case S_IFLNK:
return perms ? 'l' : '@';
case S_IFSOCK:
Expand Down Expand Up @@ -3303,16 +3307,19 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel)
addch('0' + (ent->mode & 7));

switch (ent->mode & S_IFMT) {
case S_IFDIR:
ind2 = '/'; // fallthrough
case S_IFREG:
if (ent->flags & HARD_LINK)
ln = TRUE;
if (!ind2) {
if (ent->flags & HARD_LINK)
ln = TRUE;

if (ent->mode & 0100)
ind2 = '*';
// fallthrough
case S_IFDIR:
if (!ind2) /* Add a column if end indicator is not needed */
++namecols;
if (ent->mode & 0100)
ind2 = '*';

if (!ind2) /* Add a column if end indicator is not needed */
++namecols;
}

size = coolsize(cfg.blkorder ? ent->blocks << blk_shift : ent->size);
len = 10 - (uint)strlen(size);
Expand Down Expand Up @@ -6577,6 +6584,7 @@ static void usage(void)
" -A no dir auto-select\n"
" -b key open bookmark key\n"
" -c cli-only opener (overrides -e)\n"
" -C disable color\n"
" -d detail mode\n"
" -e text in $VISUAL/$EDITOR/vi\n"
" -E use EDITOR for undetached edits\n"
Expand Down Expand Up @@ -6748,7 +6756,7 @@ int main(int argc, char *argv[])

while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
: getopt(argc, argv, "Ab:cdeEfFgHKnop:QrRs:St:T:Vxh"))) != -1) {
: getopt(argc, argv, "Ab:cCdeEfFgHKnop:QrRs:St:T:Vxh"))) != -1) {
switch (opt) {
case 'A':
cfg.autoselect = 0;
Expand All @@ -6759,6 +6767,9 @@ int main(int argc, char *argv[])
case 'c':
cfg.cliopener = 1;
break;
case 'C':
g_states |= STATE_NOCOLOR;
break;
case 'S':
cfg.blkorder = 1;
nftw_fn = sum_bsize;
Expand Down

0 comments on commit 02c02c5

Please sign in to comment.