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