3 Copyright (C) 2018 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "cli/cli-cmds.h"
22 #include "cli/cli-style.h"
24 /* True if styling is enabled. */
26 #if defined(_WIN32) || defined (__CYGWIN__)
32 /* Name of colors; must correspond to ui_file_style::basic_color. */
33 static const char * const cli_colors
[] = {
46 /* Names of intensities; must correspond to
47 ui_file_style::intensity. */
48 static const char * const cli_intensities
[] = {
55 /* See cli-style.h. */
57 cli_style_option
file_name_style (ui_file_style::GREEN
);
59 /* See cli-style.h. */
61 cli_style_option
function_name_style (ui_file_style::YELLOW
);
63 /* See cli-style.h. */
65 cli_style_option
variable_name_style (ui_file_style::CYAN
);
67 /* See cli-style.h. */
69 cli_style_option::cli_style_option (ui_file_style::basic_color fg
)
70 : m_foreground (cli_colors
[fg
- ui_file_style::NONE
]),
71 m_background (cli_colors
[0]),
72 m_intensity (cli_intensities
[ui_file_style::NORMAL
])
76 /* Return the color number corresponding to COLOR. */
79 color_number (const char *color
)
81 for (int i
= 0; i
< ARRAY_SIZE (cli_colors
); ++i
)
83 if (color
== cli_colors
[i
])
86 gdb_assert_not_reached ("color not found");
89 /* See cli-style.h. */
92 cli_style_option::style () const
94 int fg
= color_number (m_foreground
);
95 int bg
= color_number (m_background
);
96 ui_file_style::intensity intensity
= ui_file_style::NORMAL
;
98 for (int i
= 0; i
< ARRAY_SIZE (cli_intensities
); ++i
)
100 if (m_intensity
== cli_intensities
[i
])
102 intensity
= (ui_file_style::intensity
) i
;
107 return ui_file_style (fg
, bg
, intensity
);
110 /* See cli-style.h. */
113 cli_style_option::do_set (const char *args
, int from_tty
)
117 /* See cli-style.h. */
120 cli_style_option::do_show (const char *args
, int from_tty
)
124 /* See cli-style.h. */
127 cli_style_option::do_show_foreground (struct ui_file
*file
, int from_tty
,
128 struct cmd_list_element
*cmd
,
131 const char *name
= (const char *) get_cmd_context (cmd
);
132 fprintf_filtered (file
, _("The \"%s\" foreground color is: %s\n"),
136 /* See cli-style.h. */
139 cli_style_option::do_show_background (struct ui_file
*file
, int from_tty
,
140 struct cmd_list_element
*cmd
,
143 const char *name
= (const char *) get_cmd_context (cmd
);
144 fprintf_filtered (file
, _("The \"%s\" background color is: %s\n"),
148 /* See cli-style.h. */
151 cli_style_option::do_show_intensity (struct ui_file
*file
, int from_tty
,
152 struct cmd_list_element
*cmd
,
155 const char *name
= (const char *) get_cmd_context (cmd
);
156 fprintf_filtered (file
, _("The \"%s\" display intensity is: %s\n"),
160 /* See cli-style.h. */
163 cli_style_option::add_setshow_commands (const char *name
,
164 enum command_class theclass
,
165 const char *prefix_doc
,
166 const char *prefixname
,
167 struct cmd_list_element
**set_list
,
168 struct cmd_list_element
**show_list
)
170 m_show_prefix
= std::string ("set ") + prefixname
+ " ";
171 m_show_prefix
= std::string ("show ") + prefixname
+ " ";
173 add_prefix_cmd (name
, no_class
, do_set
, prefix_doc
, &m_set_list
,
174 m_show_prefix
.c_str (), 0, set_list
);
175 add_prefix_cmd (name
, no_class
, do_show
, prefix_doc
, &m_show_list
,
176 m_set_prefix
.c_str (), 0, show_list
);
178 add_setshow_enum_cmd ("foreground", theclass
, cli_colors
,
180 _("Set the foreground color for this property"),
181 _("Show the foreground color for this property"),
185 &m_set_list
, &m_show_list
, (void *) name
);
186 add_setshow_enum_cmd ("background", theclass
, cli_colors
,
188 _("Set the background color for this property"),
189 _("Show the background color for this property"),
193 &m_set_list
, &m_show_list
, (void *) name
);
194 add_setshow_enum_cmd ("intensity", theclass
, cli_intensities
,
196 _("Set the display intensity color for this property"),
198 Show the display intensity color for this property"),
202 &m_set_list
, &m_show_list
, (void *) name
);
206 set_style (const char *arg
, int from_tty
)
211 show_style (const char *arg
, int from_tty
)
216 show_style_enabled (struct ui_file
*file
, int from_tty
,
217 struct cmd_list_element
*c
, const char *value
)
220 fprintf_filtered (file
, _("CLI output styling is enabled.\n"));
222 fprintf_filtered (file
, _("CLI output styling is disabled.\n"));
226 _initialize_cli_style ()
228 static cmd_list_element
*style_set_list
;
229 static cmd_list_element
*style_show_list
;
231 add_prefix_cmd ("style", no_class
, set_style
, _("\
232 Style-specific settings\n\
233 Configure various style-related variables, such as colors"),
234 &style_set_list
, "set style ", 0, &setlist
);
235 add_prefix_cmd ("style", no_class
, show_style
, _("\
236 Style-specific settings\n\
237 Configure various style-related variables, such as colors"),
238 &style_show_list
, "show style ", 0, &showlist
);
240 add_setshow_boolean_cmd ("enabled", no_class
, &cli_styling
, _("\
241 Set whether CLI styling is enabled."), _("\
242 Show whether CLI is enabled."), _("\
243 If enabled, output to the terminal is styled."),
244 NULL
, show_style_enabled
,
245 &style_set_list
, &style_show_list
);
247 file_name_style
.add_setshow_commands ("filename", no_class
,
249 Filename display styling\n\
250 Configure filename colors and display intensity."),
254 function_name_style
.add_setshow_commands ("function", no_class
,
256 Function name display styling\n\
257 Configure function name colors and display intensity"),
261 variable_name_style
.add_setshow_commands ("variable", no_class
,
264 Variable name display styling\n\
265 Configure variable name colors and display intensity"),
This page took 0.041987 seconds and 5 git commands to generate.