]> skyeroc.xyz Git - dgamelaunch/commitdiff
Add background color functionality to ATTR()
authorsbkelley <sb24kelley@gmail.com>
Fri, 19 Jun 2026 03:47:38 +0000 (23:47 -0400)
committersbkelley <sb24kelley@gmail.com>
Fri, 19 Jun 2026 06:59:54 +0000 (02:59 -0400)
* color_pair_idx no longer compiled in if USE_NCURSES_COLOR not defined

* rename special_end to second_cursor

* Invert if statement

* Update indentation

* Flatten the other if statement

* Add fg,bg delimiter

Update dgamelaunch.conf hints

dgamelaunch.c
dgamelaunch.h
examples/dgamelaunch.conf

index 27babad0a957e7b5c90558eb714b3ecc26a0770c..bb81e218d51eb07b5d6b8b0de7b2cfe847dea8c1 100644 (file)
@@ -633,8 +633,30 @@ int remap_attr_string(char *s)
     case '0': case '1': case '2': case '3': case '4':
     case '5': case '6': case '7': case '8': case '9':
     {
-      int num = atoi(s);
-      if (num >= 0 && num <= 129)
+      char *num_delimiter;
+      int num;
+      int other_num;
+
+      if ((num_delimiter = strchr(s, ',')))
+      {
+        *num_delimiter = '\0';
+        num = atoi(s);
+        s = num_delimiter + 1;
+        other_num = atoi(s);
+
+        if (other_num >= 0 && other_num <= 7)
+        {
+          // If there's a valid background color, set that, overriding whatever
+          // came from the first number (but leaving the foreground in place)
+          num &= 15;
+          num |= other_num << 4;
+        }
+
+      }
+      else // no ',' delimiter
+        num = atoi(s);
+
+      if (num >= -1 && num <= 128)
         attr |= COLOR_PAIR(num+1);
     }
     break;
@@ -666,7 +688,7 @@ int remap_attr_string(char *s)
 void drawbanner(struct dg_banner *ban)
 {
   unsigned int i;
-  char *edit_cursor, *special_end, *next_delimiter;
+  char *edit_cursor, *second_cursor, *next_delimiter;
   int attr = 0, oattr = 0;
 
   if (!ban)
@@ -681,53 +703,47 @@ void drawbanner(struct dg_banner *ban)
     do
     { // while (line_incomplete)
       line_incomplete = 0;
-      if ((edit_cursor = strstr(output_cursor, "$ATTR(")))
+      if (!(edit_cursor = strstr(output_cursor, "$ATTR(")))
       {
-        if ((special_end = strstr(edit_cursor, ")")))
-        {
-          int delimited = 0;
-          char *next_attr_char;
-          line_incomplete = 1;
-          oattr = attr;
-          attr = A_NORMAL;
-          *edit_cursor = *special_end = '\0';
-          edit_cursor += 6;
-          next_attr_char = edit_cursor;
-          do // while(delimited)
-          {
-            delimited = 0;
-            next_delimiter = strchr(edit_cursor, ';');
-            if (next_delimiter && *next_delimiter)
-            {
-              delimited = 1;
-              next_attr_char = next_delimiter;
-              *next_attr_char = '\0';
-              next_attr_char++;
-            }
-            attr |= remap_attr_string(edit_cursor);
-            edit_cursor = next_attr_char;
-          } while (delimited);
-
-          mvaddstr(1 + i, x, output_cursor);
-          if (oattr)
-            attroff(oattr);
-          if (attr)
-            attron(attr);
-          x += strlen(output_cursor);
-          special_end++;
-          output_cursor = special_end;
-        }
-        else
-          mvaddstr(1 + i, x, output_cursor);
+        mvaddstr(1 + i, x, output_cursor);
+        break;
       }
-      else
+      if (!(second_cursor = strstr(edit_cursor, ")")))
+      {
         mvaddstr(1 + i, x, output_cursor);
-//      elif ((edit_cursor = strstr(output_cursor, "$ATT2(")))
-//      {
-//        if ((special_end = strstr(edit_cursor, ")")))
-//        {
-//        }
-//      }
+        break;
+      }
+      int delimited = 0;
+      char *next_attr_char;
+      line_incomplete = 1;
+      oattr = attr;
+      attr = A_NORMAL;
+      *edit_cursor = *second_cursor = '\0';
+      edit_cursor += 6;
+      next_attr_char = edit_cursor;
+      do // while(delimited)
+      {
+        delimited = 0;
+        next_delimiter = strchr(edit_cursor, ';');
+        if (next_delimiter && *next_delimiter)
+        {
+          delimited = 1;
+          next_attr_char = next_delimiter;
+          *next_attr_char = '\0';
+          next_attr_char++;
+        }
+        attr |= remap_attr_string(edit_cursor);
+        edit_cursor = next_attr_char;
+      } while (delimited);
+
+      mvaddstr(1 + i, x, output_cursor);
+      if (oattr)
+        attroff(oattr);
+      if (attr)
+        attron(attr);
+      x += strlen(output_cursor);
+      second_cursor++;
+      output_cursor = second_cursor;
     } while (line_incomplete);
     free(banner_line);
   }
@@ -1925,7 +1941,9 @@ initcurses ()
   clear();
   refresh();
 }
+/* ************************************************************* */
 
+#ifdef USE_NCURSES_COLOR
 int color_pair_idx(int fg, int bg)
 {
   int bgbits = (((1 & bg) << 2) | (2 & bg) | ((4 & bg) >> 2)) << 4;
@@ -1933,7 +1951,7 @@ int color_pair_idx(int fg, int bg)
   int fgbits = (8 & fg) | ((1 & fg) << 2) | (2 & fg) | ((4 & fg) >> 2);
   return (bgbits | fgbits) + 1;
 }
-
+#endif
 /* ************************************************************* */
 
 void
index c1996761a3166be9172646b8af0ec4093559ddff..92ffeacf32103b1c498d121cafe9bf5ecb731beb 100644 (file)
@@ -351,7 +351,9 @@ extern void domailuser(char *username);
 extern void drawmenu(void);
 extern void freefile(void);
 extern void initcurses(void);
+#ifdef USE_NCURSES_COLOR
 extern int color_pair_idx(int fg, int bg);
+#endif
 extern void loginprompt(int from_ttyplay);
 extern void newuser(void);
 extern void autologin(char *user, char *pass);
index 8c437284cb855311e4a578b43b71f63f58cd8be0..fede966c21f8b6e220750536f44068d8967893ed 100644 (file)
@@ -221,12 +221,17 @@ menu["mainmenu_user"] {
 # String substitutions defined in bannervars-section above.
 # $VERSION           =  dgamelaunch version
 # $USERNAME          =  user name (or [Anonymous] if not logged in)
-# $ATTR(params)      =  change text color and attributes.
-#        params can be either number (to set the text color),
-#       one, or any of "b" (bold), "s" (standout), "u" (underline),
-#       "r" (reverse) or "d" (dim),
-#       or both color number and attribute characters, separated by semicolon.
-#       Empty param resets color and attributes to default.
+# $ATTR(params)      =  change text color and attributes.                | 0 = Black
+#        params can be either number (to set the text color),            | 1 = Blue
+#       one, or any of "b" (bold), "s" (standout), "u" (underline),           | 2 = Green
+#       "r" (reverse) or "d" (dim),                                           | 3 = Cyan
+#       or both color number and attribute characters, separated by semicolon.| 4 = Red
+#       Empty param resets color and attributes to default.                   | 5 = Purple
+#  Color number can be from -1 to 128. Two color numbers can be provided,| 6 = Yellow
+#  separated by a comma (eg: $ATTR(14,1;b;f)) -- the second number must  | 7 = White
+#  be from 0-7, and will be used as the background colour.               | 8-15 = bright-bit set
+#  If no background color is given, and the provided foreground is >15,  | 16-127 = setting background bits
+#  the higher 3 bits will be used as a background color.
         bannerfile = "(:menudir:)/dgl_menu_main_user.txt"
 # after which cursor is moved to this location
 # if cursor-definition is missing, the cursor is put