]> Sergey Matveev's repositories - nnn.git/commitdiff
Reduce processing if NNN_COLORS is unset
authorArun Prakash Jana <engineerarun@gmail.com>
Sun, 2 Aug 2020 17:45:48 +0000 (23:15 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sun, 2 Aug 2020 17:45:48 +0000 (23:15 +0530)
src/nnn.c

index 336c0c195e31649d5920310616b36385b57431db..781fad81a4cb2e9471faa0a4d14c6bb0fdc52a8f 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -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);
+                       }
                }
        }