texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[7769] info allow style variables to be set


From: gavinsmith0123
Subject: [7769] info allow style variables to be set
Date: Wed, 3 May 2017 15:47:58 -0400 (EDT)

Revision: 7769
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7769
Author:   gavin
Date:     2017-05-03 15:47:57 -0400 (Wed, 03 May 2017)
Log Message:
-----------
info allow style variables to be set

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/variables.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2017-05-02 20:09:30 UTC (rev 7768)
+++ trunk/ChangeLog     2017-05-03 19:47:57 UTC (rev 7769)
@@ -1,3 +1,15 @@
+2017-01-29  Jason Hood  <address@hidden>
+
+       Allow style variables to be described and set.
+       (Patch originally submitted 2017-01-29 on bug-texinfo.)
+
+       * info/variables.c (rendition_variable): Remove.
+       (rendition_choices): New variable.
+       (info_variables): Use rendition_choices for the style variables.
+       (rendition_to_string): New variable.
+       (describe_variable, set_variable, set_variable_to_value): 
+       Special handling for style variables.
+
 2017-05-02  Gavin Smith  <address@hidden>
 
        * configure.ac: When checking for Perl XS support, set

Modified: trunk/info/variables.c
===================================================================
--- trunk/info/variables.c      2017-05-02 20:09:30 UTC (rev 7768)
+++ trunk/info/variables.c      2017-05-03 19:47:57 UTC (rev 7769)
@@ -52,10 +52,12 @@
 /* Choices for the scroll-last-node variable */
 static char *scroll_last_node_choices[] = { "Stop", "Top", NULL };
 
-/* Set choices to address of this to indicate takes a value in the
-   format for specifying renditions.  Nothing is actually stored in
-   this variable. */
-char *rendition_variable = 0;
+/* Choices for, and indicator of, renditions. */
+static char *rendition_choices[] = { "black", "red", "green", "yellow", "blue",
+    "magenta", "cyan", "white", "nocolour", "bgblack", "bgred", "bggreen",
+    "bgyellow", "bgblue", "bgmagenta", "bgcyan", "bgwhite", "nobgcolour",
+    "underline", "nounderline", "standout", "nostandout", "bold", "regular",
+    "blink", "noblink", NULL };
 
 /* Address of this indicates the 'highlight-searches' variable. */
 static int *highlight_searches;
@@ -146,15 +148,15 @@
 
   { "link-style",
       N_("Styles for links"),
-    &ref_rendition, &rendition_variable },
+    &ref_rendition, (char **)rendition_choices },
 
   { "active-link-style",
       N_("Styles for active links"),
-    &hl_ref_rendition, &rendition_variable },
+    &hl_ref_rendition, (char **)rendition_choices },
 
   { "match-style",
       N_("Styles for search matches"),
-    &match_rendition, &rendition_variable },
+    &match_rendition, (char **)rendition_choices },
 
   { "nodeline",
       N_("How to print the information line at the start of a node"),
@@ -163,7 +165,61 @@
   { NULL }
 };
 
+static char *
+rendition_to_string (RENDITION *rendition)
+{
+  static char string[8 /* nocolour */ + 1 /* comma */
+                     + 10 /* nobgcolour */ + 1
+                     + 11 /* nounderline */ + 1
+                     + 10 /* nostandout */ + 1
+                     + 7 /* regular */ + 1
+                     + 7 /* noblink */ + 1];
+  unsigned long style;
+  static const char* fg[] = { "black", "red", "green", "yellow", "blue",
+      "magenta", "cyan", "white" };
+  static const char* bg[] = { "bgblack", "bgred", "bggreen", "bgyellow",
+      "bgblue", "bgmagenta", "bgcyan", "bgwhite" };
 
+  *string = '\0';
+
+  if (rendition->mask & BLINK_MASK)
+    strcat (string, rendition->value & BLINK_MASK ? "blink" : "noblink");
+  if (rendition->mask & BOLD_MASK)
+    {
+      if (*string != '\0')
+        strcat (string, ",");
+      strcat (string, rendition->value & BOLD_MASK ? "bold" : "nobold");
+    }
+  if (rendition->mask & STANDOUT_MASK)
+    {
+      if (*string != '\0')
+        strcat (string, ",");
+      strcat (string, rendition->value & STANDOUT_MASK ? "standout" : 
"nostandout");
+    }
+  if (rendition->mask & UNDERLINE_MASK)
+    {
+      if (*string != '\0')
+        strcat (string, ",");
+      strcat (string, rendition->value & UNDERLINE_MASK ? "underline" : 
"nounderline");
+    }
+  if (rendition->mask & COLOUR_MASK)
+    {
+      if (*string != '\0')
+        strcat (string, ",");
+      style = rendition->value & COLOUR_MASK;
+      strcat (string, style >= 8 ? fg[style - 8] : "nocolour");
+    }
+  if (rendition->mask & BGCOLOUR_MASK)
+    {
+      if (*string != '\0')
+        strcat (string, ",");
+      style = (rendition->value & BGCOLOUR_MASK) >> 9;
+      strcat (string, style >= 8 ? bg[style - 8] : "nobgcolour");
+    }
+
+  return string;
+}
+
 DECLARE_INFO_COMMAND (describe_variable, _("Explain the use of a variable"))
 {
   VARIABLE_ALIST *var;
@@ -176,7 +232,12 @@
 
   if (var->choices)
     asprintf (&description, "%s (%s): %s.",
-             var->name, var->choices[*(int *)var->value], _(var->doc));
+             var->name,
+             var->value == &highlight_searches
+             ? on_off_choices[match_rendition.mask != 0]
+             : var->choices == (char **) &rendition_choices
+             ? rendition_to_string (var->value)
+             : var->choices[*(int *)var->value], _(var->doc));
   else
     asprintf (&description, "%s (%d): %s.",
              var->name, *(int *)var->value, _(var->doc));
@@ -243,10 +304,18 @@
         }
 
       sprintf (prompt, _("Set %s to value (%s): "),
-               var->name, var->choices[*(int *)(var->value)]);
+               var->name,
+               var->value == &highlight_searches
+               ? on_off_choices[match_rendition.mask != 0]
+               : var->choices == (char **) &rendition_choices
+               ? rendition_to_string (var->value)
+               : var->choices[*(int *)(var->value)]);
 
       /* Ask the completer to read a variable value for us. */
-      line = info_read_completing_in_echo_area (prompt, array);
+      if (var->choices == (char **) &rendition_choices)
+        line = info_read_maybe_completing (prompt, array);
+      else
+        line = info_read_completing_in_echo_area (prompt, array);
 
       info_free_references (array);
 
@@ -361,10 +430,18 @@
          "match-rendition=standout". */
       if (var->value == &highlight_searches)
         {
-          match_rendition.mask = STANDOUT_MASK;
-          match_rendition.value = STANDOUT_MASK;
+          if (strcmp (on_off_choices[0], value) == 0)
+            {
+              match_rendition.mask = 0;
+              match_rendition.value = 0;
+            }
+          else
+            {
+              match_rendition.mask = STANDOUT_MASK;
+              match_rendition.value = STANDOUT_MASK;
+            }
         }
-      else if (var->choices != (char **) &rendition_variable)
+      else if (var->choices != (char **) &rendition_choices)
         {
           /* Find the choice in our list of choices. */
           for (j = 0; var->choices[j]; j++)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]