diff options
author | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2019-05-31 13:47:37 +0200 |
---|---|---|
committer | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2019-06-03 21:59:11 +0200 |
commit | 9303eb2fb1630678def10613c81215c2bd21d278 (patch) | |
tree | a2282608bb0422631678012ddfe7ee36c1c1fef4 /gdb/cli | |
parent | 79b377b3cf3a0e71e1e4710c4ee1e65e7a27a5d4 (diff) | |
download | binutils-9303eb2fb1630678def10613c81215c2bd21d278.zip binutils-9303eb2fb1630678def10613c81215c2bd21d278.tar.gz binutils-9303eb2fb1630678def10613c81215c2bd21d278.tar.bz2 |
Add highlight style, title style, fputs_highlighted. Improve 'show style'
Have 'show style' and its subcommands using a style to style its output.
This allows the GDB user or developer to use 'show style' to visually see
with one command how all the current styles look like.
Add 2 new styles highlight style, title style and fputs_highlighted function.
Highlight style is used by fputs_highlighted to highlight the parts of
its char *STR argument that match a HIGHLIGHT regexp.
This (and the title style) will be used in a following patch.
Diffstat (limited to 'gdb/cli')
-rw-r--r-- | gdb/cli/cli-style.c | 117 | ||||
-rw-r--r-- | gdb/cli/cli-style.h | 21 |
2 files changed, 104 insertions, 34 deletions
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index f6f6c7b..fb6486b 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -61,29 +61,50 @@ static const char * const cli_intensities[] = { /* See cli-style.h. */ -cli_style_option file_name_style (ui_file_style::GREEN); +cli_style_option file_name_style ("filename", ui_file_style::GREEN); /* See cli-style.h. */ -cli_style_option function_name_style (ui_file_style::YELLOW); +cli_style_option function_name_style ("function", ui_file_style::YELLOW); /* See cli-style.h. */ -cli_style_option variable_name_style (ui_file_style::CYAN); +cli_style_option variable_name_style ("variable", ui_file_style::CYAN); /* See cli-style.h. */ -cli_style_option address_style (ui_file_style::BLUE); +cli_style_option address_style ("address", ui_file_style::BLUE); /* See cli-style.h. */ -cli_style_option::cli_style_option (ui_file_style::basic_color fg) - : m_foreground (cli_colors[fg - ui_file_style::NONE]), +cli_style_option highlight_style ("highlight", ui_file_style::RED); + +/* See cli-style.h. */ + +cli_style_option title_style ("title", ui_file_style::BOLD); + +/* See cli-style.h. */ + +cli_style_option::cli_style_option (const char *name, + ui_file_style::basic_color fg) + : m_name (name), + m_foreground (cli_colors[fg - ui_file_style::NONE]), m_background (cli_colors[0]), m_intensity (cli_intensities[ui_file_style::NORMAL]) { } +/* See cli-style.h. */ + +cli_style_option::cli_style_option (const char *name, + ui_file_style::intensity i) + : m_name (name), + m_foreground (cli_colors[0]), + m_background (cli_colors[0]), + m_intensity (cli_intensities[i]) +{ +} + /* Return the color number corresponding to COLOR. */ static int @@ -118,6 +139,21 @@ cli_style_option::style () const return ui_file_style (fg, bg, intensity); } +/* Implements the cli_style_option::do_show_* functions. + WHAT and VALUE are the property and value to show. + The style for which WHAT is shown is retrieved from CMD context. */ + +static void +do_show (const char *what, struct ui_file *file, + struct cmd_list_element *cmd, + const char *value) +{ + cli_style_option *cso = (cli_style_option *) get_cmd_context (cmd); + fputs_filtered (_("The "), file); + fprintf_styled (file, cso->style (), _("\"%s\" style"), cso->name ()); + fprintf_filtered (file, _(" %s is: %s\n"), what, value); +} + /* See cli-style.h. */ void @@ -125,9 +161,7 @@ cli_style_option::do_show_foreground (struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value) { - const char *name = (const char *) get_cmd_context (cmd); - fprintf_filtered (file, _("The \"%s\" foreground color is: %s\n"), - name, value); + do_show (_("foreground color"), file, cmd, value); } /* See cli-style.h. */ @@ -137,9 +171,7 @@ cli_style_option::do_show_background (struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value) { - const char *name = (const char *) get_cmd_context (cmd); - fprintf_filtered (file, _("The \"%s\" background color is: %s\n"), - name, value); + do_show (_("background color"), file, cmd, value); } /* See cli-style.h. */ @@ -149,16 +181,13 @@ cli_style_option::do_show_intensity (struct ui_file *file, int from_tty, struct cmd_list_element *cmd, const char *value) { - const char *name = (const char *) get_cmd_context (cmd); - fprintf_filtered (file, _("The \"%s\" display intensity is: %s\n"), - name, value); + do_show (_("display intensity"), file, cmd, value); } /* See cli-style.h. */ void -cli_style_option::add_setshow_commands (const char *name, - enum command_class theclass, +cli_style_option::add_setshow_commands (enum command_class theclass, const char *prefix_doc, struct cmd_list_element **set_list, void (*do_set) (const char *args, @@ -167,12 +196,12 @@ cli_style_option::add_setshow_commands (const char *name, void (*do_show) (const char *args, int from_tty)) { - m_set_prefix = std::string ("set style ") + name + " "; - m_show_prefix = std::string ("show style ") + name + " "; + m_set_prefix = std::string ("set style ") + m_name + " "; + m_show_prefix = std::string ("show style ") + m_name + " "; - add_prefix_cmd (name, no_class, do_set, prefix_doc, &m_set_list, + add_prefix_cmd (m_name, no_class, do_set, prefix_doc, &m_set_list, m_set_prefix.c_str (), 0, set_list); - add_prefix_cmd (name, no_class, do_show, prefix_doc, &m_show_list, + add_prefix_cmd (m_name, no_class, do_show, prefix_doc, &m_show_list, m_show_prefix.c_str (), 0, show_list); add_setshow_enum_cmd ("foreground", theclass, cli_colors, @@ -182,7 +211,7 @@ cli_style_option::add_setshow_commands (const char *name, nullptr, nullptr, do_show_foreground, - &m_set_list, &m_show_list, (void *) name); + &m_set_list, &m_show_list, (void *) this); add_setshow_enum_cmd ("background", theclass, cli_colors, &m_background, _("Set the background color for this property"), @@ -190,7 +219,7 @@ cli_style_option::add_setshow_commands (const char *name, nullptr, nullptr, do_show_background, - &m_set_list, &m_show_list, (void *) name); + &m_set_list, &m_show_list, (void *) this); add_setshow_enum_cmd ("intensity", theclass, cli_intensities, &m_intensity, _("Set the display intensity for this property"), @@ -198,7 +227,7 @@ cli_style_option::add_setshow_commands (const char *name, nullptr, nullptr, do_show_intensity, - &m_set_list, &m_show_list, (void *) name); + &m_set_list, &m_show_list, (void *) this); } static cmd_list_element *style_set_list; @@ -245,6 +274,18 @@ show_style_sources (struct ui_file *file, int from_tty, fprintf_filtered (file, _("Source code styling is disabled.\n")); } +/* Builds the "set style NAME " prefix. */ + +static std::string +set_style_name (const char *name) +{ + std::string result ("set style "); + + result += name; + result += " "; + return result; +} + void _initialize_cli_style () { @@ -278,14 +319,14 @@ it was not linked against GNU Source Highlight." ), set_style_enabled, show_style_sources, &style_set_list, &style_show_list); -#define STYLE_ADD_SETSHOW_COMMANDS(STYLE, NAME, PREFIX_DOC) \ - STYLE.add_setshow_commands (NAME, no_class, PREFIX_DOC, \ +#define STYLE_ADD_SETSHOW_COMMANDS(STYLE, PREFIX_DOC) \ + STYLE.add_setshow_commands (no_class, PREFIX_DOC, \ &style_set_list, \ [] (const char *args, int from_tty) \ { \ help_list \ (STYLE.set_list (), \ - "set style " NAME " ", \ + set_style_name (STYLE.name ()).c_str (), \ all_commands, \ gdb_stdout); \ }, \ @@ -298,23 +339,37 @@ it was not linked against GNU Source Highlight." ""); \ }) - STYLE_ADD_SETSHOW_COMMANDS (file_name_style, "filename", + STYLE_ADD_SETSHOW_COMMANDS (file_name_style, _("\ Filename display styling\n\ Configure filename colors and display intensity.")); - STYLE_ADD_SETSHOW_COMMANDS (function_name_style, "function", + STYLE_ADD_SETSHOW_COMMANDS (function_name_style, _("\ Function name display styling\n\ Configure function name colors and display intensity")); - STYLE_ADD_SETSHOW_COMMANDS (variable_name_style, "variable", + STYLE_ADD_SETSHOW_COMMANDS (variable_name_style, _("\ Variable name display styling\n\ Configure variable name colors and display intensity")); - STYLE_ADD_SETSHOW_COMMANDS (address_style, "address", + STYLE_ADD_SETSHOW_COMMANDS (address_style, _("\ Address display styling\n\ Configure address colors and display intensity")); + + STYLE_ADD_SETSHOW_COMMANDS (title_style, + _("\ +Title display styling\n\ +Configure title colors and display intensity\n\ +Some commands (such as \"apropos -v REGEXP\") use the title style to improve\n\ +readability.")); + + STYLE_ADD_SETSHOW_COMMANDS (highlight_style, + _("\ +Highlight display styling\n\ +Configure highlight colors and display intensity\n\ +Some commands use the highlight style to draw the attention to a part\n\ +of their output.")); } diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index c0520f9..6ae265e 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -28,15 +28,20 @@ class cli_style_option public: /* Construct a CLI style option with a foreground color. */ - cli_style_option (ui_file_style::basic_color fg); + cli_style_option (const char *name, ui_file_style::basic_color fg); + + /* Construct a CLI style option with an intensity. */ + cli_style_option (const char *name, ui_file_style::intensity i); /* Return a ui_file_style corresponding to the settings in this CLI style. */ ui_file_style style () const; + /* Return the style name. */ + const char *name () { return m_name; }; + /* Call once to register this CLI style with the CLI engine. */ - void add_setshow_commands (const char *name, - enum command_class theclass, + void add_setshow_commands (enum command_class theclass, const char *prefix_doc, struct cmd_list_element **set_list, void (*do_set) (const char *args, int from_tty), @@ -52,6 +57,9 @@ public: private: + /* The style name. */ + const char *m_name; + /* The foreground. */ const char *m_foreground; /* The background. */ @@ -93,6 +101,13 @@ extern cli_style_option variable_name_style; /* The address style. */ extern cli_style_option address_style; +/* The highlight style. */ +extern cli_style_option highlight_style; + +/* The title style. */ +extern cli_style_option title_style; + + /* True if source styling is enabled. */ extern int source_styling; |