aboutsummaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-11-17 11:49:25 -0700
committerTom Tromey <tom@tromey.com>2018-12-28 12:49:49 -0700
commitef1dfa3644f02efffa11d718fe5788c05177587b (patch)
tree8c1591c01d1019356b0d76e142e3fe2091c6c550 /gdb/utils.c
parentcbe5657196d0d3acbeca39973f93f333ecedacda (diff)
downloadgdb-ef1dfa3644f02efffa11d718fe5788c05177587b.zip
gdb-ef1dfa3644f02efffa11d718fe5788c05177587b.tar.gz
gdb-ef1dfa3644f02efffa11d718fe5788c05177587b.tar.bz2
Reset terminal styles
This adds a function that can be used to reset terminal styles, regardless of what style the low-level output routines currently think is applied. This is used to make "echo" and "printf" work properly when emitting ANSI terminal escapes -- now gdb will reset the style at the end of the command. gdb/ChangeLog 2018-12-28 Tom Tromey <tom@tromey.com> * utils.h (reset_terminal_style): Declare. * utils.c (can_emit_style_escape): New function. (set_output_style): Use it. (reset_terminal_style): New function. * printcmd.c (printf_command): Call reset_terminal_style. * cli/cli-cmds.c (echo_command): Call reset_terminal_style.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index 2fb7476..4bb2f34 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1444,25 +1444,50 @@ emit_style_escape (const ui_file_style &style)
wrap_buffer.append (style.to_ansi ());
}
-/* Set the current output style. This will affect future uses of the
- _filtered output functions. */
+/* Return true if ANSI escapes can be used on STREAM. */
-static void
-set_output_style (struct ui_file *stream, const ui_file_style &style)
+static bool
+can_emit_style_escape (struct ui_file *stream)
{
if (stream != gdb_stdout
|| !cli_styling
- || style == desired_style
|| !ui_file_isatty (stream))
- return;
+ return false;
const char *term = getenv ("TERM");
if (term == nullptr || !strcmp (term, "dumb"))
+ return false;
+ return true;
+}
+
+/* Set the current output style. This will affect future uses of the
+ _filtered output functions. */
+
+static void
+set_output_style (struct ui_file *stream, const ui_file_style &style)
+{
+ if (!can_emit_style_escape (stream)
+ || style == desired_style)
return;
desired_style = style;
emit_style_escape (style);
}
+/* See utils.h. */
+
+void
+reset_terminal_style (struct ui_file *stream)
+{
+ if (can_emit_style_escape (stream))
+ {
+ /* Force the setting, regardless of what we think the setting
+ might already be. */
+ desired_style = ui_file_style ();
+ applied_style = desired_style;
+ wrap_buffer.append (desired_style.to_ansi ());
+ }
+}
+
/* Wait, so the user can read what's on the screen. Prompt the user
to continue by pressing RETURN. 'q' is also provided because
telling users what to do in the prompt is more user-friendly than