diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2020-08-02 23:15:48 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2020-08-02 23:15:48 +0530 |
commit | b948423a80759becf7c1ca2c9831960b5b43c5f8 (patch) | |
tree | 27d68faa9a2f152419b34cd62d7e1f161b68864e /src/nnn.c | |
parent | 359b6f7a37292f3545da86fa3fb3866683227dfd (diff) | |
download | nnn-b948423a80759becf7c1ca2c9831960b5b43c5f8.tar.gz |
Reduce processing if NNN_COLORS is unset
Diffstat (limited to 'src/nnn.c')
-rw-r--r-- | src/nnn.c | 74 |
1 files changed, 38 insertions, 36 deletions
@@ -1586,54 +1586,56 @@ static bool initcurses(void *oldmask) char *colors = getenv(env_cfg[NNN_COLORS]); if (colors || !getenv("NO_COLOR")) { - uint *pcode; + uint *pclr; char ch; bool ext = FALSE; start_color(); use_default_colors(); - if (colors && *colors == '#') { - char *sep = strchr(colors, ';'); + if (colors) { + if (*colors == '#') { + char *sep = strchr(colors, ';'); - if (COLORS >= 256) { - ++colors; - ext = TRUE; - - /* - * If fallback colors are specified, set the separator - * to NULL so we don't interpret separator and fallback - * if fewer than CTX_MAX xterm 256 colors are specified. - */ - if (sep) - *sep = '\0'; - } else { - colors = sep; /* Detect if 8 colors fallback is appended */ - if (colors) + if (COLORS >= 256) { ++colors; - } - } - - /* Get and set the context colors */ - for (uchar i = 0; i < CTX_MAX; ++i) { - pcode = &g_ctx[i].color; + ext = TRUE; - if (colors && *colors) { - if (ext) { - ch = *colors; - if (*++colors) { - *pcode = (16 * xchartohex(ch)) + xchartohex(*colors); - ++colors; - } else - *pcode = xchartohex(ch); + /* + * If fallback colors are specified, set the separator + * to NULL so we don't interpret separator and fallback + * if fewer than CTX_MAX xterm 256 colors are specified. + */ + if (sep) + *sep = '\0'; } else { - *pcode = (*colors < '0' || *colors > '7') ? 4 : *colors - '0'; - ++colors; + colors = sep; /* Detect if 8 colors fallback is appended */ + if (colors) + ++colors; } - } else - *pcode = 4; + } + + /* Get and set the context colors */ + for (uchar i = 0; i < CTX_MAX; ++i) { + pclr = &g_ctx[i].color; + + if (*colors) { + if (ext) { + ch = *colors; + if (*++colors) { + *pclr = (16 * xchartohex(ch)) + xchartohex(*colors); + ++colors; + } else + *pclr = xchartohex(ch); + } else { + *pclr = (*colors < '0' || *colors > '7') ? 4 : *colors - '0'; + ++colors; + } + } else + *pclr = 4; - init_pair(i + 1, *pcode, -1); + init_pair(i + 1, *pclr, -1); + } } } |