rotate gdb/ChangeLog
[deliverable/binutils-gdb.git] / gdb / cli / cli-style.c
CommitLineData
cbe56571
TT
1/* CLI colorizing
2
3 Copyright (C) 2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "defs.h"
21#include "cli/cli-cmds.h"
22#include "cli/cli-style.h"
62f29fda 23#include "source-cache.h"
cbe56571
TT
24
25/* True if styling is enabled. */
26
27#if defined(_WIN32) || defined (__CYGWIN__)
28int cli_styling = 0;
29#else
30int cli_styling = 1;
31#endif
32
33/* Name of colors; must correspond to ui_file_style::basic_color. */
34static const char * const cli_colors[] = {
35 "none",
36 "black",
37 "red",
38 "green",
39 "yellow",
40 "blue",
41 "magenta",
42 "cyan",
43 "white",
44 nullptr
45};
46
47/* Names of intensities; must correspond to
48 ui_file_style::intensity. */
49static const char * const cli_intensities[] = {
50 "normal",
51 "bold",
52 "dim",
53 nullptr
54};
55
56/* See cli-style.h. */
57
58cli_style_option file_name_style (ui_file_style::GREEN);
59
60/* See cli-style.h. */
61
62cli_style_option function_name_style (ui_file_style::YELLOW);
63
64/* See cli-style.h. */
65
80ae2043
TT
66cli_style_option variable_name_style (ui_file_style::CYAN);
67
68/* See cli-style.h. */
69
35fb8261
TT
70cli_style_option address_style (ui_file_style::BLUE);
71
72/* See cli-style.h. */
73
cbe56571
TT
74cli_style_option::cli_style_option (ui_file_style::basic_color fg)
75 : m_foreground (cli_colors[fg - ui_file_style::NONE]),
76 m_background (cli_colors[0]),
77 m_intensity (cli_intensities[ui_file_style::NORMAL])
78{
79}
80
81/* Return the color number corresponding to COLOR. */
82
83static int
84color_number (const char *color)
85{
86 for (int i = 0; i < ARRAY_SIZE (cli_colors); ++i)
87 {
88 if (color == cli_colors[i])
89 return i - 1;
90 }
91 gdb_assert_not_reached ("color not found");
92}
93
94/* See cli-style.h. */
95
96ui_file_style
97cli_style_option::style () const
98{
99 int fg = color_number (m_foreground);
100 int bg = color_number (m_background);
101 ui_file_style::intensity intensity = ui_file_style::NORMAL;
102
103 for (int i = 0; i < ARRAY_SIZE (cli_intensities); ++i)
104 {
105 if (m_intensity == cli_intensities[i])
106 {
107 intensity = (ui_file_style::intensity) i;
108 break;
109 }
110 }
111
112 return ui_file_style (fg, bg, intensity);
113}
114
115/* See cli-style.h. */
116
117void
118cli_style_option::do_set (const char *args, int from_tty)
119{
120}
121
122/* See cli-style.h. */
123
124void
125cli_style_option::do_show (const char *args, int from_tty)
126{
127}
128
129/* See cli-style.h. */
130
131void
132cli_style_option::do_show_foreground (struct ui_file *file, int from_tty,
133 struct cmd_list_element *cmd,
134 const char *value)
135{
136 const char *name = (const char *) get_cmd_context (cmd);
137 fprintf_filtered (file, _("The \"%s\" foreground color is: %s\n"),
138 name, value);
139}
140
141/* See cli-style.h. */
142
143void
144cli_style_option::do_show_background (struct ui_file *file, int from_tty,
145 struct cmd_list_element *cmd,
146 const char *value)
147{
148 const char *name = (const char *) get_cmd_context (cmd);
149 fprintf_filtered (file, _("The \"%s\" background color is: %s\n"),
150 name, value);
151}
152
153/* See cli-style.h. */
154
155void
156cli_style_option::do_show_intensity (struct ui_file *file, int from_tty,
157 struct cmd_list_element *cmd,
158 const char *value)
159{
160 const char *name = (const char *) get_cmd_context (cmd);
161 fprintf_filtered (file, _("The \"%s\" display intensity is: %s\n"),
162 name, value);
163}
164
165/* See cli-style.h. */
166
167void
168cli_style_option::add_setshow_commands (const char *name,
169 enum command_class theclass,
170 const char *prefix_doc,
171 const char *prefixname,
172 struct cmd_list_element **set_list,
173 struct cmd_list_element **show_list)
174{
ecad3b21 175 m_set_prefix = std::string ("set ") + prefixname + " ";
cbe56571
TT
176 m_show_prefix = std::string ("show ") + prefixname + " ";
177
178 add_prefix_cmd (name, no_class, do_set, prefix_doc, &m_set_list,
ecad3b21 179 m_set_prefix.c_str (), 0, set_list);
cbe56571 180 add_prefix_cmd (name, no_class, do_show, prefix_doc, &m_show_list,
ecad3b21 181 m_show_prefix.c_str (), 0, show_list);
cbe56571
TT
182
183 add_setshow_enum_cmd ("foreground", theclass, cli_colors,
184 &m_foreground,
185 _("Set the foreground color for this property"),
186 _("Show the foreground color for this property"),
187 nullptr,
188 nullptr,
189 do_show_foreground,
190 &m_set_list, &m_show_list, (void *) name);
191 add_setshow_enum_cmd ("background", theclass, cli_colors,
192 &m_background,
193 _("Set the background color for this property"),
194 _("Show the background color for this property"),
195 nullptr,
196 nullptr,
197 do_show_background,
198 &m_set_list, &m_show_list, (void *) name);
199 add_setshow_enum_cmd ("intensity", theclass, cli_intensities,
200 &m_intensity,
201 _("Set the display intensity color for this property"),
202 _("\
203Show the display intensity color for this property"),
204 nullptr,
205 nullptr,
206 do_show_intensity,
207 &m_set_list, &m_show_list, (void *) name);
208}
209
210static void
211set_style (const char *arg, int from_tty)
212{
213}
214
215static void
216show_style (const char *arg, int from_tty)
217{
218}
219
62f29fda
TT
220static void
221set_style_enabled (const char *args, int from_tty, struct cmd_list_element *c)
222{
223 g_source_cache.clear ();
224}
225
cbe56571
TT
226static void
227show_style_enabled (struct ui_file *file, int from_tty,
228 struct cmd_list_element *c, const char *value)
229{
230 if (cli_styling)
231 fprintf_filtered (file, _("CLI output styling is enabled.\n"));
232 else
233 fprintf_filtered (file, _("CLI output styling is disabled.\n"));
234}
235
236void
237_initialize_cli_style ()
238{
239 static cmd_list_element *style_set_list;
240 static cmd_list_element *style_show_list;
241
242 add_prefix_cmd ("style", no_class, set_style, _("\
243Style-specific settings\n\
244Configure various style-related variables, such as colors"),
245 &style_set_list, "set style ", 0, &setlist);
246 add_prefix_cmd ("style", no_class, show_style, _("\
247Style-specific settings\n\
248Configure various style-related variables, such as colors"),
249 &style_show_list, "show style ", 0, &showlist);
250
251 add_setshow_boolean_cmd ("enabled", no_class, &cli_styling, _("\
252Set whether CLI styling is enabled."), _("\
253Show whether CLI is enabled."), _("\
254If enabled, output to the terminal is styled."),
62f29fda 255 set_style_enabled, show_style_enabled,
cbe56571
TT
256 &style_set_list, &style_show_list);
257
258 file_name_style.add_setshow_commands ("filename", no_class,
259 _("\
260Filename display styling\n\
261Configure filename colors and display intensity."),
262 "style filename",
263 &style_set_list,
264 &style_show_list);
265 function_name_style.add_setshow_commands ("function", no_class,
266 _("\
267Function name display styling\n\
268Configure function name colors and display intensity"),
269 "style function",
270 &style_set_list,
271 &style_show_list);
80ae2043 272 variable_name_style.add_setshow_commands ("variable", no_class,
80ae2043
TT
273 _("\
274Variable name display styling\n\
275Configure variable name colors and display intensity"),
ecad3b21 276 "style variable",
80ae2043
TT
277 &style_set_list,
278 &style_show_list);
35fb8261 279 address_style.add_setshow_commands ("address", no_class,
35fb8261
TT
280 _("\
281Address display styling\n\
282Configure address colors and display intensity"),
ecad3b21 283 "style address",
35fb8261
TT
284 &style_set_list,
285 &style_show_list);
cbe56571 286}
This page took 0.053888 seconds and 4 git commands to generate.