3 Copyright (C) 2018-2020 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"
23 #include "source-cache.h"
24 #include "observable.h"
26 /* True if styling is enabled. */
28 #if defined (__MSDOS__)
29 bool cli_styling
= false;
31 bool cli_styling
= true;
34 /* True if source styling is enabled. Note that this is only
35 consulted when cli_styling is true. */
37 bool source_styling
= true;
39 /* Name of colors; must correspond to ui_file_style::basic_color. */
40 static const char * const cli_colors
[] = {
53 /* Names of intensities; must correspond to
54 ui_file_style::intensity. */
55 static const char * const cli_intensities
[] = {
62 /* See cli-style.h. */
64 cli_style_option
file_name_style ("filename", ui_file_style::GREEN
);
66 /* See cli-style.h. */
68 cli_style_option
function_name_style ("function", ui_file_style::YELLOW
);
70 /* See cli-style.h. */
72 cli_style_option
variable_name_style ("variable", ui_file_style::CYAN
);
74 /* See cli-style.h. */
76 cli_style_option
address_style ("address", ui_file_style::BLUE
);
78 /* See cli-style.h. */
80 cli_style_option
highlight_style ("highlight", ui_file_style::RED
);
82 /* See cli-style.h. */
84 cli_style_option
title_style ("title", ui_file_style::BOLD
);
86 /* See cli-style.h. */
88 cli_style_option
tui_border_style ("tui-border", ui_file_style::CYAN
);
90 /* See cli-style.h. */
92 cli_style_option
tui_active_border_style ("tui-active-border",
95 /* See cli-style.h. */
97 cli_style_option
metadata_style ("metadata", ui_file_style::DIM
);
99 /* See cli-style.h. */
101 cli_style_option::cli_style_option (const char *name
,
102 ui_file_style::basic_color fg
)
105 m_foreground (cli_colors
[fg
- ui_file_style::NONE
]),
106 m_background (cli_colors
[0]),
107 m_intensity (cli_intensities
[ui_file_style::NORMAL
])
111 /* See cli-style.h. */
113 cli_style_option::cli_style_option (const char *name
,
114 ui_file_style::intensity i
)
117 m_foreground (cli_colors
[0]),
118 m_background (cli_colors
[0]),
119 m_intensity (cli_intensities
[i
])
123 /* Return the color number corresponding to COLOR. */
126 color_number (const char *color
)
128 for (int i
= 0; i
< ARRAY_SIZE (cli_colors
); ++i
)
130 if (color
== cli_colors
[i
])
133 gdb_assert_not_reached ("color not found");
136 /* See cli-style.h. */
139 cli_style_option::style () const
141 int fg
= color_number (m_foreground
);
142 int bg
= color_number (m_background
);
143 ui_file_style::intensity intensity
= ui_file_style::NORMAL
;
145 for (int i
= 0; i
< ARRAY_SIZE (cli_intensities
); ++i
)
147 if (m_intensity
== cli_intensities
[i
])
149 intensity
= (ui_file_style::intensity
) i
;
154 return ui_file_style (fg
, bg
, intensity
);
157 /* See cli-style.h. */
160 cli_style_option::do_set_value (const char *ignore
, int from_tty
,
161 struct cmd_list_element
*cmd
)
163 cli_style_option
*cso
= (cli_style_option
*) get_cmd_context (cmd
);
164 cso
->changed
.notify ();
167 /* Implements the cli_style_option::do_show_* functions.
168 WHAT and VALUE are the property and value to show.
169 The style for which WHAT is shown is retrieved from CMD context. */
172 do_show (const char *what
, struct ui_file
*file
,
173 struct cmd_list_element
*cmd
,
176 cli_style_option
*cso
= (cli_style_option
*) get_cmd_context (cmd
);
177 fputs_filtered (_("The "), file
);
178 fprintf_styled (file
, cso
->style (), _("\"%s\" style"), cso
->name ());
179 fprintf_filtered (file
, _(" %s is: %s\n"), what
, value
);
182 /* See cli-style.h. */
185 cli_style_option::do_show_foreground (struct ui_file
*file
, int from_tty
,
186 struct cmd_list_element
*cmd
,
189 do_show (_("foreground color"), file
, cmd
, value
);
192 /* See cli-style.h. */
195 cli_style_option::do_show_background (struct ui_file
*file
, int from_tty
,
196 struct cmd_list_element
*cmd
,
199 do_show (_("background color"), file
, cmd
, value
);
202 /* See cli-style.h. */
205 cli_style_option::do_show_intensity (struct ui_file
*file
, int from_tty
,
206 struct cmd_list_element
*cmd
,
209 do_show (_("display intensity"), file
, cmd
, value
);
212 /* See cli-style.h. */
215 cli_style_option::add_setshow_commands (enum command_class theclass
,
216 const char *prefix_doc
,
217 struct cmd_list_element
**set_list
,
218 struct cmd_list_element
**show_list
,
221 m_set_prefix
= std::string ("set style ") + m_name
+ " ";
222 m_show_prefix
= std::string ("show style ") + m_name
+ " ";
224 add_basic_prefix_cmd (m_name
, no_class
, prefix_doc
, &m_set_list
,
225 m_set_prefix
.c_str (), 0, set_list
);
226 add_show_prefix_cmd (m_name
, no_class
, prefix_doc
, &m_show_list
,
227 m_show_prefix
.c_str (), 0, show_list
);
229 add_setshow_enum_cmd ("foreground", theclass
, cli_colors
,
231 _("Set the foreground color for this property."),
232 _("Show the foreground color for this property."),
236 &m_set_list
, &m_show_list
, (void *) this);
237 add_setshow_enum_cmd ("background", theclass
, cli_colors
,
239 _("Set the background color for this property."),
240 _("Show the background color for this property."),
244 &m_set_list
, &m_show_list
, (void *) this);
246 add_setshow_enum_cmd ("intensity", theclass
, cli_intensities
,
248 _("Set the display intensity for this property."),
249 _("Show the display intensity for this property."),
253 &m_set_list
, &m_show_list
, (void *) this);
256 static cmd_list_element
*style_set_list
;
257 static cmd_list_element
*style_show_list
;
260 set_style_enabled (const char *args
, int from_tty
, struct cmd_list_element
*c
)
262 g_source_cache
.clear ();
263 gdb::observers::source_styling_changed
.notify ();
267 show_style_enabled (struct ui_file
*file
, int from_tty
,
268 struct cmd_list_element
*c
, const char *value
)
271 fprintf_filtered (file
, _("CLI output styling is enabled.\n"));
273 fprintf_filtered (file
, _("CLI output styling is disabled.\n"));
277 show_style_sources (struct ui_file
*file
, int from_tty
,
278 struct cmd_list_element
*c
, const char *value
)
281 fprintf_filtered (file
, _("Source code styling is enabled.\n"));
283 fprintf_filtered (file
, _("Source code styling is disabled.\n"));
286 void _initialize_cli_style ();
288 _initialize_cli_style ()
290 add_basic_prefix_cmd ("style", no_class
, _("\
291 Style-specific settings.\n\
292 Configure various style-related variables, such as colors"),
293 &style_set_list
, "set style ", 0, &setlist
);
294 add_show_prefix_cmd ("style", no_class
, _("\
295 Style-specific settings.\n\
296 Configure various style-related variables, such as colors"),
297 &style_show_list
, "show style ", 0, &showlist
);
299 add_setshow_boolean_cmd ("enabled", no_class
, &cli_styling
, _("\
300 Set whether CLI styling is enabled."), _("\
301 Show whether CLI is enabled."), _("\
302 If enabled, output to the terminal is styled."),
303 set_style_enabled
, show_style_enabled
,
304 &style_set_list
, &style_show_list
);
306 add_setshow_boolean_cmd ("sources", no_class
, &source_styling
, _("\
307 Set whether source code styling is enabled."), _("\
308 Show whether source code styling is enabled."), _("\
309 If enabled, source code is styled.\n"
310 #ifdef HAVE_SOURCE_HIGHLIGHT
311 "Note that source styling only works if styling in general is enabled,\n\
312 see \"show style enabled\"."
314 "Source highlighting may be disabled in this installation of gdb, because\n\
315 it was not linked against GNU Source Highlight. However, it might still be\n\
316 available if the appropriate extension is available at runtime."
318 ), set_style_enabled
, show_style_sources
,
319 &style_set_list
, &style_show_list
);
321 file_name_style
.add_setshow_commands (no_class
, _("\
322 Filename display styling.\n\
323 Configure filename colors and display intensity."),
324 &style_set_list
, &style_show_list
,
327 function_name_style
.add_setshow_commands (no_class
, _("\
328 Function name display styling.\n\
329 Configure function name colors and display intensity"),
330 &style_set_list
, &style_show_list
,
333 variable_name_style
.add_setshow_commands (no_class
, _("\
334 Variable name display styling.\n\
335 Configure variable name colors and display intensity"),
336 &style_set_list
, &style_show_list
,
339 address_style
.add_setshow_commands (no_class
, _("\
340 Address display styling.\n\
341 Configure address colors and display intensity"),
342 &style_set_list
, &style_show_list
,
345 title_style
.add_setshow_commands (no_class
, _("\
346 Title display styling.\n\
347 Configure title colors and display intensity\n\
348 Some commands (such as \"apropos -v REGEXP\") use the title style to improve\n\
350 &style_set_list
, &style_show_list
,
353 highlight_style
.add_setshow_commands (no_class
, _("\
354 Highlight display styling.\n\
355 Configure highlight colors and display intensity\n\
356 Some commands use the highlight style to draw the attention to a part\n\
358 &style_set_list
, &style_show_list
,
361 metadata_style
.add_setshow_commands (no_class
, _("\
362 Metadata display styling.\n\
363 Configure metadata colors and display intensity\n\
364 The \"metadata\" style is used when GDB displays information about\n\
365 your data, for example \"<unavailable>\""),
366 &style_set_list
, &style_show_list
,
369 tui_border_style
.add_setshow_commands (no_class
, _("\
370 TUI border display styling.\n\
371 Configure TUI border colors\n\
372 The \"tui-border\" style is used when GDB displays the border of a\n\
373 TUI window that does not have the focus."),
374 &style_set_list
, &style_show_list
,
377 tui_active_border_style
.add_setshow_commands (no_class
, _("\
378 TUI active border display styling.\n\
379 Configure TUI active border colors\n\
380 The \"tui-active-border\" style is used when GDB displays the border of a\n\
381 TUI window that does have the focus."),
This page took 0.038786 seconds and 4 git commands to generate.