binutils-gdb/gdb/cli/cli-style.h
Andrew Burgess 9d2d8a16e1 gdb: add new version style
This commit adds a new 'version' style, which replaces the hard coded
styling currently used for GDB's version string.  GDB's version number
is displayed:

  1. In the output of 'show version', and

  2. When GDB starts up (without the --quiet option).

This new style can only ever affect the first of these two cases as
the second case is printed before GDB has processed any initialization
files, or processed any GDB commands passed on the command line.

However, because the first case exists I think this commit makes
sense, it means the style is no longer hard coded into GDB, and we can
add some tests that the style can be enabled/disabled correctly.

This commit is an alternative to a patch Tom posted here:

  https://sourceware.org/pipermail/gdb-patches/2020-June/169820.html

I've used the style name 'version' instead of 'startup' to reflect
what the style is actually used for.  If other parts of the startup
text end up being highlighted I imagine they would get their own
styles based on what is being highlighted.  I feel this is more inline
with the other style names that are already in use within GDB.

I also decoupled adding this style from the idea of startup options,
and the possibility of auto-saving startup options.  Those ideas can
be explored in later patches.

This commit should probably be considered only a partial solution to
issue PR cli/25956.  The colours of the style are no longer hard
coded, however, it is still impossible to change the styling of the
version string displayed during startup, so in one sense, the styling
of that string is still "hard coded".  A later patch will hopefully
extend GDB to allow it to adjust the version styling before the
initial version string is printed.

gdb/ChangeLog:

	PR cli/25956
	* cli/cli-style.c: Add 'cli/cli-setshow.h' include.
	(version_style): Define.
	(cli_style_option::cli_style_option): Add intensity parameter, and
	use as appropriate.
	(_initialize_cli_style): Register version style set/show commands.
	* cli/cli-style.h (cli_style_option): Add intensity parameter.
	(version_style): Declare.
	* top.c (print_gdb_version): Use version_stype, and styled_string
	to print the GDB version string.

gdb/doc/ChangeLog:

	PR cli/25956
	* gdb.texinfo (Output Styling): Document version style.

gdb/testsuite/ChangeLog:

	PR cli/25956
	* gdb.base/style.exp (run_style_tests): Add version string test.
	(test_startup_version_string): Use version style name.
	* lib/gdb-utils.exp (style): Handle version style name.
2021-01-22 19:09:31 +00:00

138 lines
4.2 KiB
C++

/* CLI stylizing
Copyright (C) 2018-2021 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef CLI_CLI_STYLE_H
#define CLI_CLI_STYLE_H
#include "ui-file.h"
#include "command.h"
#include "gdbsupport/observable.h"
/* A single CLI style option. */
class cli_style_option
{
public:
/* Construct a CLI style option with a foreground color. */
cli_style_option (const char *name, ui_file_style::basic_color fg,
ui_file_style::intensity = ui_file_style::NORMAL);
/* 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 (enum command_class theclass,
const char *prefix_doc,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list,
bool skip_intensity);
/* Return the 'set style NAME' command list, that can be used
to build a lambda DO_SET to call add_setshow_commands. */
struct cmd_list_element *set_list () { return m_set_list; };
/* Same as SET_LIST but for the show command list. */
struct cmd_list_element *show_list () { return m_show_list; };
/* This style can be observed for any changes. */
gdb::observers::observable<> changed;
private:
/* The style name. */
const char *m_name;
/* The foreground. */
const char *m_foreground;
/* The background. */
const char *m_background;
/* The intensity. */
const char *m_intensity;
/* Storage for prefixes needed when registering the commands. */
std::string m_show_prefix;
std::string m_set_prefix;
/* Storage for command lists needed when registering
subcommands. */
struct cmd_list_element *m_set_list = nullptr;
struct cmd_list_element *m_show_list = nullptr;
/* Callback to notify the observable. */
static void do_set_value (const char *ignore, int from_tty,
struct cmd_list_element *cmd);
/* Callback to show the foreground. */
static void do_show_foreground (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value);
/* Callback to show the background. */
static void do_show_background (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value);
/* Callback to show the intensity. */
static void do_show_intensity (struct ui_file *file, int from_tty,
struct cmd_list_element *cmd,
const char *value);
};
/* The file name style. */
extern cli_style_option file_name_style;
/* The function name style. */
extern cli_style_option function_name_style;
/* The variable name style. */
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;
/* The metadata style. */
extern cli_style_option metadata_style;
/* The border style of a TUI window that does not have the focus. */
extern cli_style_option tui_border_style;
/* The border style of a TUI window that does have the focus. */
extern cli_style_option tui_active_border_style;
/* The style to use for the GDB version string. */
extern cli_style_option version_style;
/* True if source styling is enabled. */
extern bool source_styling;
/* True if styling is enabled. */
extern bool cli_styling;
#endif /* CLI_CLI_STYLE_H */