From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 06/16] Reset terminal styles
Date: Wed, 28 Nov 2018 00:14:00 -0000 [thread overview]
Message-ID: <20181128001435.12703-7-tom@tromey.com> (raw)
In-Reply-To: <20181128001435.12703-1-tom@tromey.com>
This adds a function that can be used to reset terminal styles,
regardless of what style the low-levle 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-11-27 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.
---
gdb/ChangeLog | 9 +++++++++
gdb/cli/cli-cmds.c | 2 ++
gdb/printcmd.c | 2 ++
gdb/utils.c | 37 +++++++++++++++++++++++++++++++------
gdb/utils.h | 4 ++++
5 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 135f550b80..12ac74c7e9 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -689,6 +689,8 @@ echo_command (const char *text, int from_tty)
printf_filtered ("%c", c);
}
+ reset_terminal_style (gdb_stdout);
+
/* Force this output to appear now. */
wrap_here ("");
gdb_flush (gdb_stdout);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 8c999188d7..79c3d2d2ff 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2609,6 +2609,8 @@ static void
printf_command (const char *arg, int from_tty)
{
ui_printf (arg, gdb_stdout);
+ reset_terminal_style (gdb_stdout);
+ wrap_here ("");
gdb_flush (gdb_stdout);
}
diff --git a/gdb/utils.c b/gdb/utils.c
index 69c9e76576..85b0fb14e3 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
diff --git a/gdb/utils.h b/gdb/utils.h
index 9872a15fd7..1f09ec2d47 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -439,6 +439,10 @@ extern void fputs_styled (const char *linebuffer,
const ui_file_style &style,
struct ui_file *stream);
+/* Reset the terminal style to the default, if needed. */
+
+extern void reset_terminal_style (struct ui_file *stream);
+
/* Display the host ADDR on STREAM formatted as ``0x%x''. */
extern void gdb_print_host_address_1 (const void *addr, struct ui_file *stream);
--
2.17.2
next prev parent reply other threads:[~2018-11-28 0:14 UTC|newest]
Thread overview: 99+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-28 0:16 [PATCH 00/16] Add styling to the gdb CLI and TUI Tom Tromey
2018-11-28 0:14 ` [PATCH 12/16] Style addresses Tom Tromey
2018-11-28 0:14 ` [PATCH 09/16] Style print_address_symbolic Tom Tromey
2018-11-28 0:14 ` [PATCH 05/16] Add output styles to gdb Tom Tromey
2018-12-24 4:08 ` Joel Brobecker
2018-12-28 18:55 ` Tom Tromey
2018-11-28 0:14 ` [PATCH 03/16] Introduce ui_file_style Tom Tromey
2018-12-24 3:40 ` Joel Brobecker
2018-12-28 18:54 ` Tom Tromey
2018-11-28 0:14 ` [PATCH 02/16] Add a "context" argument to add_setshow_enum_cmd Tom Tromey
2018-11-28 0:14 ` [PATCH 14/16] Use wclrtoeol in tui_show_source_line Tom Tromey
2018-12-24 8:03 ` Joel Brobecker
2018-11-28 0:14 ` Tom Tromey [this message]
2018-12-24 4:16 ` [PATCH 06/16] Reset terminal styles Joel Brobecker
2018-12-28 19:01 ` Tom Tromey
2018-11-28 0:14 ` [PATCH 10/16] Style the gdb welcome message Tom Tromey
2018-11-28 0:16 ` [PATCH 07/16] Style variable names Tom Tromey
2018-11-28 0:16 ` [PATCH 16/16] Document the "set style" commands Tom Tromey
2018-11-28 6:51 ` Eli Zaretskii
2018-12-28 19:19 ` Tom Tromey
2018-11-28 0:16 ` [PATCH 11/16] Style the "Reading symbols" message Tom Tromey
2018-11-28 0:16 ` [PATCH 15/16] Highlight source code using GNU Source Highlight Tom Tromey
2019-11-16 0:58 ` Andrew Pinski
2019-11-16 8:19 ` Eli Zaretskii
2019-11-24 17:41 ` Tom Tromey
2019-11-24 18:13 ` Christian Biesinger via gdb-patches
2019-11-24 19:53 ` Tom Tromey
2018-11-28 0:16 ` [PATCH 08/16] Style locations when setting a breakpoint Tom Tromey
2018-11-28 0:16 ` [PATCH 04/16] Change gdb test suite's TERM setting Tom Tromey
2018-11-28 0:16 ` [PATCH 13/16] Make ANSI terminal escape sequences work in TUI Tom Tromey
2018-12-24 8:02 ` Joel Brobecker
2018-12-28 19:42 ` Tom Tromey
2018-11-28 0:19 ` [PATCH 01/16] Change wrap buffering to use a std::string Tom Tromey
2018-12-23 15:26 ` Joel Brobecker
2018-12-28 18:47 ` Tom Tromey
2018-11-28 7:02 ` [PATCH 00/16] Add styling to the gdb CLI and TUI Eli Zaretskii
2018-11-29 22:44 ` Tom Tromey
2018-11-30 7:02 ` Eli Zaretskii
2018-11-30 16:17 ` Tom Tromey
2018-12-23 10:49 ` Joel Brobecker
2019-03-01 13:10 ` Pedro Alves
2019-03-01 13:56 ` Eli Zaretskii
2019-03-01 14:10 ` Pedro Alves
2019-03-01 14:50 ` Eli Zaretskii
2019-03-01 7:47 ` Eli Zaretskii
2019-03-01 18:42 ` Tom Tromey
2019-03-01 19:40 ` Eli Zaretskii
2019-03-01 21:04 ` Tom Tromey
2019-03-02 7:15 ` Eli Zaretskii
2019-03-03 15:42 ` Eli Zaretskii
2019-03-04 15:08 ` Tom Tromey
2019-03-04 15:57 ` Eli Zaretskii
2019-03-04 16:16 ` Tom Tromey
2019-03-05 15:38 ` Eli Zaretskii
2019-03-08 14:55 ` Eli Zaretskii
2019-03-08 16:14 ` Hannes Domani via gdb-patches
2019-03-08 21:08 ` Tom Tromey
2019-03-08 21:11 ` Tom Tromey
2019-03-09 6:49 ` Eli Zaretskii
2019-03-03 15:53 ` Eli Zaretskii
2019-03-03 16:16 ` Matt Rice
2019-03-03 17:13 ` Eli Zaretskii
2019-03-03 18:04 ` Matt Rice
2019-03-04 15:01 ` Tom Tromey
2019-03-04 17:37 ` Eli Zaretskii
2019-03-04 17:40 ` Tom Tromey
2019-03-06 16:02 ` Eli Zaretskii
2019-03-20 19:35 ` GDB version as convenience variable Eli Zaretskii
2019-03-25 17:31 ` Eli Zaretskii
2019-03-25 17:58 ` Simon Marchi
2019-03-25 18:10 ` Eli Zaretskii
2019-03-25 18:33 ` Simon Marchi
2019-03-25 18:37 ` Simon Marchi
2019-03-25 18:43 ` Eli Zaretskii
2019-03-25 18:51 ` Simon Marchi
2019-03-25 19:19 ` Eli Zaretskii
2019-03-26 14:47 ` Simon Marchi
2019-03-26 20:57 ` Joel Brobecker
2019-03-27 3:34 ` Eli Zaretskii
2019-03-27 12:56 ` Joel Brobecker
2019-03-30 17:25 ` Simon Marchi
2019-03-30 10:01 ` Eli Zaretskii
2019-03-21 1:55 ` [PATCH 00/16] Add styling to the gdb CLI and TUI Simon Marchi
2019-03-21 14:38 ` Eli Zaretskii
2019-03-21 15:02 ` Simon Marchi
2019-03-21 16:01 ` Eli Zaretskii
2019-03-21 16:06 ` Simon Marchi
2019-03-21 16:12 ` Pedro Alves
2019-03-21 16:54 ` John Baldwin
2019-03-21 17:02 ` Eli Zaretskii
2019-03-21 18:08 ` Simon Marchi
2019-03-21 18:19 ` Pedro Alves
2019-03-21 18:38 ` Eli Zaretskii
2019-03-07 6:02 ` Joel Brobecker
2019-03-07 14:53 ` Eli Zaretskii
2019-03-08 5:40 ` Joel Brobecker
2019-03-04 16:04 ` Eli Zaretskii
2018-12-24 9:27 ` Joel Brobecker
2018-12-28 20:57 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181128001435.12703-7-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox