]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make cli_styling static within cli/cli-style.c
authorAndrew Burgess <aburgess@redhat.com>
Mon, 17 Feb 2025 15:00:52 +0000 (15:00 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 17 Mar 2025 16:59:13 +0000 (16:59 +0000)
The cli_styling variable is controlled by 'set style enabled on|off'
user setting, and is currently globally visible.

In a couple of places we access this variable directly, though in
ui-file.c the accesses are all performed through term_cli_styling(),
which is a function that wraps checking cli_styling along with a check
that GDB's terminal supports styling.

In a future commit, I'd plan to add a new parameter to gdb.execute()
which will allow styling to be temporarily suppressed.  In an earlier
proposal, I made gdb.execute() disable styling by changing the value
of cli_styling, however, this approach has a problem.

If gdb.execute() is used to run 'show style enabled', the changing
cli_styling will change what is printed.  Similarly, if gdb.execute()
is used to execute 'set style enabled on|off' then having
gdb.execute() save and restore the value of cli_styling will undo the
adjustment from 'set style enabled ...'.

So what I plan to do in the future, is add a new control flag which
can be used to temporarily disable styling.

To make this new control variable easier to add, lets force everyone
to call term_cli_styling() to check if styling is enabled or not.  To
force everyone to use term_cli_styling() this commit makes cli_styling
static within gdb/cli/cli-style.c.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/cli/cli-style.c
gdb/cli/cli-style.h
gdb/main.c
gdb/tui/tui-wingeneral.c
gdb/ui-file.c

index 47f7d2ea693bc37c02deb5eb19cc2ce01d8aa48a..3ca30a4fa7f7a01895b8f39e68297878d20b8276 100644 (file)
@@ -27,9 +27,9 @@
 /* True if styling is enabled.  */
 
 #if defined (__MSDOS__)
-bool cli_styling = false;
+static bool cli_styling = false;
 #else
-bool cli_styling = true;
+static bool cli_styling = true;
 #endif
 
 /* True if source styling is enabled.  Note that this is only
@@ -80,6 +80,22 @@ terminal_supports_styling ()
 
 /* See cli/cli-style.h.  */
 
+void
+disable_cli_styling ()
+{
+  cli_styling = false;
+}
+
+/* See cli/cli-style.h.  */
+
+bool
+term_cli_styling ()
+{
+  return cli_styling;
+}
+
+/* See cli/cli-style.h.  */
+
 void
 disable_styling_from_environment ()
 {
index 1fb89a37455aadbfe7f98723e8111b8c265a5b15..18827ce9d54d4c8f98a666f28ea0c3642676770a 100644 (file)
@@ -157,13 +157,18 @@ extern bool source_styling;
 /* True if disassembler styling is enabled.  */
 extern bool disassembler_styling;
 
-/* True if styling is enabled.  */
-extern bool cli_styling;
-
 /* Check for environment variables that indicate styling should start as
    disabled.  If any are found then disable styling.  Styling is never
    enabled by this call.  If styling was already disabled then it remains
    disabled after this call.  */
 extern void disable_styling_from_environment ();
 
+/* Equivalent to 'set style enabled off'.  Can be used during GDB's start
+   up if a command line option, or environment variable, indicates that
+   styling should be turned off.  */
+extern void disable_cli_styling ();
+
+/* Return true styled output is currently enabled.  */
+extern bool term_cli_styling ();
+
 #endif /* GDB_CLI_CLI_STYLE_H */
index 2545a1579245831f4df576db0d556694c306e4f7..27043b748855e11fe359c982c3da1d3916aa4a74 100644 (file)
@@ -1027,7 +1027,7 @@ captured_main_1 (struct captured_main_args *context)
        quiet = 1;
 
        /* Disable all output styling when running in batch mode.  */
-       cli_styling = false;
+       disable_cli_styling ();
       }
   }
 
index 56e7abd8f2c3748e06334ed0314e042a04a1c4ab..90fdaceb1a27a72632147747ada1d8cf06156a28 100644 (file)
@@ -80,7 +80,7 @@ box_win (struct tui_win_info *win_info,
 
   /* tui_apply_style resets the style entirely, so be sure to call it
      before applying ATTRS.  */
-  if (cli_styling)
+  if (term_cli_styling ())
     tui_apply_style (win, (highlight_flag
                           ? tui_active_border_style.style ()
                           : tui_border_style.style ()));
index 1a2f5635b7655121ac71000929d140a620677104..e9d3a907e6fb50f47d93d483946b560e7fe24eea 100644 (file)
@@ -180,16 +180,6 @@ null_file::write_async_safe (const char *buf, long sizeof_buf)
 
 \f
 
-/* Return true if styling is currently enabled.  */
-
-static bool
-term_cli_styling ()
-{
-  return cli_styling;
-}
-
-\f
-
 string_file::~string_file ()
 {}