aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-style.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/cli/cli-style.c')
-rw-r--r--gdb/cli/cli-style.c139
1 files changed, 134 insertions, 5 deletions
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index 3ca30a4..d6829f0 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -1,6 +1,6 @@
/* CLI colorizing
- Copyright (C) 2018-2024 Free Software Foundation, Inc.
+ Copyright (C) 2018-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -23,6 +23,7 @@
#include "cli/cli-style.h"
#include "source-cache.h"
#include "observable.h"
+#include "charset.h"
/* True if styling is enabled. */
@@ -42,6 +43,10 @@ bool source_styling = true;
bool disassembler_styling = true;
+/* User-settable variable controlling emoji output. */
+
+static auto_boolean emoji_styling = AUTO_BOOLEAN_AUTO;
+
/* Names of intensities; must correspond to
ui_file_style::intensity. */
static const char * const cli_intensities[] = {
@@ -51,6 +56,25 @@ static const char * const cli_intensities[] = {
nullptr
};
+/* When true styling is being temporarily suppressed. */
+
+static bool scoped_disable_styling_p = false;
+
+/* See cli/cli-style.h. */
+
+scoped_disable_styling::scoped_disable_styling ()
+{
+ m_old_value = scoped_disable_styling_p;
+ scoped_disable_styling_p = true;
+}
+
+/* See cli/cli-style.h. */
+
+scoped_disable_styling::~scoped_disable_styling ()
+{
+ scoped_disable_styling_p = m_old_value;
+}
+
/* Return true if GDB's output terminal should support styling, otherwise,
return false. This function really checks for things that indicate
styling might not be supported, so a return value of false indicates
@@ -91,7 +115,7 @@ disable_cli_styling ()
bool
term_cli_styling ()
{
- return cli_styling;
+ return cli_styling && !scoped_disable_styling_p;
}
/* See cli/cli-style.h. */
@@ -353,7 +377,9 @@ set_style_enabled (const char *args, int from_tty, struct cmd_list_element *c)
warning ("The current terminal doesn't support styling. Styled output "
"might not appear as expected.");
- g_source_cache.clear ();
+ /* It is not necessary to flush the source cache here. The source cache
+ tracks whether entries are styled or not. */
+
gdb::observers::styling_changed.notify ();
}
@@ -389,9 +415,86 @@ show_style_disassembler (struct ui_file *file, int from_tty,
gdb_printf (file, _("Disassembler output styling is disabled.\n"));
}
-void _initialize_cli_style ();
+/* Implement 'show style emoji'. */
+
+static void
+show_emoji_styling (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ if (emoji_styling == AUTO_BOOLEAN_TRUE)
+ gdb_printf (file, _("CLI emoji styling is enabled.\n"));
+ else if (emoji_styling == AUTO_BOOLEAN_FALSE)
+ gdb_printf (file, _("CLI emoji styling is disabled.\n"));
+ else
+ gdb_printf (file, _("CLI emoji styling is automatic (currently %s).\n"),
+ emojis_ok () ? _("enabled") : _("disabled"));
+}
+
+/* See cli-style.h. */
+
+bool
+emojis_ok ()
+{
+ if (!cli_styling || emoji_styling == AUTO_BOOLEAN_FALSE)
+ return false;
+ if (emoji_styling == AUTO_BOOLEAN_TRUE)
+ return true;
+ return strcmp (host_charset (), "UTF-8") == 0;
+}
+
+/* See cli-style.h. */
+
void
-_initialize_cli_style ()
+no_emojis ()
+{
+ emoji_styling = AUTO_BOOLEAN_FALSE;
+}
+
+/* Emoji warning prefix. */
+static std::string warning_prefix = "⚠️ ";
+
+/* Implement 'show style warning-prefix'. */
+
+static void
+show_warning_prefix (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ gdb_printf (file, _("Warning prefix is \"%s\".\n"),
+ warning_prefix.c_str ());
+}
+
+/* See cli-style.h. */
+
+void
+print_warning_prefix (ui_file *file)
+{
+ if (emojis_ok ())
+ gdb_puts (warning_prefix.c_str (), file);
+}
+
+/* Emoji error prefix. */
+static std::string error_prefix = "❌️ ";
+
+/* Implement 'show style error-prefix'. */
+
+static void
+show_error_prefix (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ gdb_printf (file, _("Error prefix is \"%s\".\n"),
+ error_prefix.c_str ());
+}
+
+/* See cli-style.h. */
+
+void
+print_error_prefix (ui_file *file)
+{
+ if (emojis_ok ())
+ gdb_puts (error_prefix.c_str (), file);
+}
+
+INIT_GDB_FILE (cli_style)
{
add_setshow_prefix_cmd ("style", no_class,
_("\
@@ -410,6 +513,13 @@ If enabled, output to the terminal is styled."),
set_style_enabled, show_style_enabled,
&style_set_list, &style_show_list);
+ add_setshow_auto_boolean_cmd ("emoji", no_class, &emoji_styling, _("\
+Set whether emoji output is enabled."), _("\
+Show whether emoji output is enabled."), _("\
+If enabled, emojis may be displayed."),
+ nullptr, show_emoji_styling,
+ &style_set_list, &style_show_list);
+
add_setshow_boolean_cmd ("sources", no_class, &source_styling, _("\
Set whether source code styling is enabled."), _("\
Show whether source code styling is enabled."), _("\
@@ -606,4 +716,23 @@ coming from your source code."),
&style_disasm_set_list);
add_alias_cmd ("symbol", function_prefix_cmds.show, no_class, 0,
&style_disasm_show_list);
+
+ add_setshow_string_cmd ("warning-prefix", no_class,
+ &warning_prefix,
+ _("Set the warning prefix text."),
+ _("Show the warning prefix text."),
+ _("\
+The warning prefix text is displayed before any warning, when\n\
+emoji output is enabled."),
+ nullptr, show_warning_prefix,
+ &style_set_list, &style_show_list);
+ add_setshow_string_cmd ("error-prefix", no_class,
+ &error_prefix,
+ _("Set the error prefix text."),
+ _("Show the error prefix text."),
+ _("\
+The error prefix text is displayed before any error, when\n\
+emoji output is enabled."),
+ nullptr, show_error_prefix,
+ &style_set_list, &style_show_list);
}