]>
Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI window generic functions. |
f33c6cbf | 2 | |
1d506c26 | 3 | Copyright (C) 1998-2024 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 | 5 | Contributed by Hewlett-Packard Company. |
c906108c | 6 | |
f377b406 SC |
7 | This file is part of GDB. |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
f377b406 SC |
21 | |
22 | /* This module contains procedures for handling tui window functions | |
23 | like resize, scrolling, scrolling, changing focus, etc. | |
24 | ||
25 | Author: Susan B. Macchia */ | |
c906108c | 26 | |
c906108c SS |
27 | #include "command.h" |
28 | #include "symtab.h" | |
29 | #include "breakpoint.h" | |
30 | #include "frame.h" | |
41783295 | 31 | #include "cli/cli-cmds.h" |
a2a7af0c | 32 | #include "cli/cli-style.h" |
3e752b04 | 33 | #include "top.h" |
52575520 | 34 | #include "source.h" |
400b5eca | 35 | #include "gdbsupport/event-loop.h" |
45e42163 | 36 | #include "gdbcmd.h" |
93b54c8e | 37 | #include "async-event.h" |
deb1ba4e | 38 | #include "utils.h" |
c906108c | 39 | |
d7b2e967 | 40 | #include "tui/tui.h" |
c4ef48c6 | 41 | #include "tui/tui-io.h" |
ce38393b | 42 | #include "tui/tui-command.h" |
d7b2e967 | 43 | #include "tui/tui-data.h" |
3df505f6 | 44 | #include "tui/tui-layout.h" |
d7b2e967 | 45 | #include "tui/tui-wingeneral.h" |
cf2ef009 | 46 | #include "tui/tui-status.h" |
d7b2e967 AC |
47 | #include "tui/tui-regs.h" |
48 | #include "tui/tui-disasm.h" | |
49 | #include "tui/tui-source.h" | |
50 | #include "tui/tui-winsource.h" | |
2c0b251b | 51 | #include "tui/tui-win.h" |
c906108c | 52 | |
6a83354a | 53 | #include "gdb_curses.h" |
96ec9981 | 54 | #include <ctype.h> |
dbda9972 | 55 | #include "readline/readline.h" |
8082468f | 56 | #include <string_view> |
96ec9981 | 57 | |
9612b5ec UW |
58 | #include <signal.h> |
59 | ||
0b39b52e TT |
60 | static void tui_set_tab_width_command (const char *, int); |
61 | static void tui_refresh_all_command (const char *, int); | |
1d12d88f | 62 | static void tui_all_windows_info (const char *, int); |
0b39b52e TT |
63 | static void tui_scroll_forward_command (const char *, int); |
64 | static void tui_scroll_backward_command (const char *, int); | |
65 | static void tui_scroll_left_command (const char *, int); | |
66 | static void tui_scroll_right_command (const char *, int); | |
67 | static void parse_scrolling_args (const char *, | |
08ef48c5 MS |
68 | struct tui_win_info **, |
69 | int *); | |
c906108c SS |
70 | |
71 | ||
17aae570 SC |
72 | #ifndef ACS_LRCORNER |
73 | # define ACS_LRCORNER '+' | |
74 | #endif | |
75 | #ifndef ACS_LLCORNER | |
76 | # define ACS_LLCORNER '+' | |
77 | #endif | |
78 | #ifndef ACS_ULCORNER | |
79 | # define ACS_ULCORNER '+' | |
80 | #endif | |
81 | #ifndef ACS_URCORNER | |
82 | # define ACS_URCORNER '+' | |
83 | #endif | |
84 | #ifndef ACS_HLINE | |
85 | # define ACS_HLINE '-' | |
86 | #endif | |
87 | #ifndef ACS_VLINE | |
88 | # define ACS_VLINE '|' | |
89 | #endif | |
90 | ||
af101512 | 91 | /* Possible values for tui-border-kind variable. */ |
40478521 | 92 | static const char *const tui_border_kind_enums[] = { |
af101512 SC |
93 | "space", |
94 | "ascii", | |
95 | "acs", | |
96 | NULL | |
97 | }; | |
98 | ||
99 | /* Possible values for tui-border-mode and tui-active-border-mode. */ | |
40478521 | 100 | static const char *const tui_border_mode_enums[] = { |
af101512 SC |
101 | "normal", |
102 | "standout", | |
103 | "reverse", | |
104 | "half", | |
105 | "half-standout", | |
106 | "bold", | |
107 | "bold-standout", | |
108 | NULL | |
109 | }; | |
110 | ||
111 | struct tui_translate | |
112 | { | |
113 | const char *name; | |
114 | int value; | |
115 | }; | |
116 | ||
117 | /* Translation table for border-mode variables. | |
ec1115b3 | 118 | The list of values must be terminated by a NULL. */ |
3d34df0a | 119 | static struct tui_translate tui_border_mode_translate[] = { |
af101512 SC |
120 | { "normal", A_NORMAL }, |
121 | { "standout", A_STANDOUT }, | |
122 | { "reverse", A_REVERSE }, | |
123 | { "half", A_DIM }, | |
124 | { "half-standout", A_DIM | A_STANDOUT }, | |
125 | { "bold", A_BOLD }, | |
126 | { "bold-standout", A_BOLD | A_STANDOUT }, | |
ec1115b3 | 127 | { 0, 0 } |
af101512 SC |
128 | }; |
129 | ||
275cef13 TV |
130 | /* Translation tables for border-kind (acs excluded), one for vline, hline and |
131 | corners (see wborder, border curses operations). */ | |
3d34df0a | 132 | static struct tui_translate tui_border_kind_translate_vline[] = { |
af101512 SC |
133 | { "space", ' ' }, |
134 | { "ascii", '|' }, | |
ec1115b3 | 135 | { 0, 0 } |
af101512 SC |
136 | }; |
137 | ||
3d34df0a | 138 | static struct tui_translate tui_border_kind_translate_hline[] = { |
af101512 SC |
139 | { "space", ' ' }, |
140 | { "ascii", '-' }, | |
ec1115b3 | 141 | { 0, 0 } |
af101512 SC |
142 | }; |
143 | ||
275cef13 | 144 | static struct tui_translate tui_border_kind_translate_corner[] = { |
af101512 SC |
145 | { "space", ' ' }, |
146 | { "ascii", '+' }, | |
ec1115b3 | 147 | { 0, 0 } |
af101512 SC |
148 | }; |
149 | ||
150 | ||
151 | /* Tui configuration variables controlled with set/show command. */ | |
3d34df0a | 152 | static const char *tui_active_border_mode = "bold-standout"; |
920d2a44 | 153 | static void |
08ef48c5 MS |
154 | show_tui_active_border_mode (struct ui_file *file, |
155 | int from_tty, | |
156 | struct cmd_list_element *c, | |
157 | const char *value) | |
920d2a44 | 158 | { |
6cb06a8c | 159 | gdb_printf (file, _("\ |
920d2a44 | 160 | The attribute mode to use for the active TUI window border is \"%s\".\n"), |
6cb06a8c | 161 | value); |
920d2a44 AC |
162 | } |
163 | ||
3d34df0a | 164 | static const char *tui_border_mode = "normal"; |
920d2a44 | 165 | static void |
08ef48c5 MS |
166 | show_tui_border_mode (struct ui_file *file, |
167 | int from_tty, | |
168 | struct cmd_list_element *c, | |
169 | const char *value) | |
920d2a44 | 170 | { |
6cb06a8c | 171 | gdb_printf (file, _("\ |
920d2a44 | 172 | The attribute mode to use for the TUI window borders is \"%s\".\n"), |
6cb06a8c | 173 | value); |
920d2a44 AC |
174 | } |
175 | ||
3d34df0a | 176 | static const char *tui_border_kind = "acs"; |
920d2a44 | 177 | static void |
08ef48c5 MS |
178 | show_tui_border_kind (struct ui_file *file, |
179 | int from_tty, | |
180 | struct cmd_list_element *c, | |
181 | const char *value) | |
920d2a44 | 182 | { |
6cb06a8c TT |
183 | gdb_printf (file, _("The kind of border for TUI windows is \"%s\".\n"), |
184 | value); | |
920d2a44 AC |
185 | } |
186 | ||
92c1d07d PA |
187 | /* Implementation of the "set/show style tui-current-position" commands. */ |
188 | ||
189 | bool style_tui_current_position = false; | |
190 | ||
191 | static void | |
192 | show_style_tui_current_position (ui_file *file, | |
193 | int from_tty, | |
194 | cmd_list_element *c, | |
195 | const char *value) | |
196 | { | |
197 | gdb_printf (file, _("\ | |
198 | Styling the text highlighted by the TUI's current position indicator is %s.\n"), | |
199 | value); | |
200 | } | |
201 | ||
202 | static void | |
203 | set_style_tui_current_position (const char *ignore, int from_tty, | |
204 | cmd_list_element *c) | |
205 | { | |
206 | if (TUI_SRC_WIN != nullptr) | |
207 | TUI_SRC_WIN->refill (); | |
208 | if (TUI_DISASM_WIN != nullptr) | |
209 | TUI_DISASM_WIN->refill (); | |
210 | } | |
af101512 | 211 | |
1cc6d956 MS |
212 | /* Tui internal configuration variables. These variables are updated |
213 | by tui_update_variables to reflect the tui configuration | |
af101512 SC |
214 | variables. */ |
215 | chtype tui_border_vline; | |
216 | chtype tui_border_hline; | |
217 | chtype tui_border_ulcorner; | |
218 | chtype tui_border_urcorner; | |
219 | chtype tui_border_llcorner; | |
220 | chtype tui_border_lrcorner; | |
221 | ||
222 | int tui_border_attrs; | |
223 | int tui_active_border_attrs; | |
224 | ||
664ac93f TV |
225 | /* Identify the item in the translation table, and return the corresponding value. */ |
226 | static int | |
af101512 SC |
227 | translate (const char *name, struct tui_translate *table) |
228 | { | |
229 | while (table->name) | |
230 | { | |
231 | if (name && strcmp (table->name, name) == 0) | |
664ac93f | 232 | return table->value; |
af101512 SC |
233 | table++; |
234 | } | |
235 | ||
ec1115b3 | 236 | gdb_assert_not_reached (""); |
af101512 SC |
237 | } |
238 | ||
0bad8af9 TV |
239 | /* Translate NAME to a value. If NAME is "acs", use ACS_CHAR. Otherwise, use |
240 | translation table TABLE. */ | |
241 | static int | |
242 | translate_acs (const char *name, struct tui_translate *table, int acs_char) | |
243 | { | |
244 | /* The ACS characters are determined at run time by curses terminal | |
245 | management. */ | |
246 | if (strcmp (name, "acs") == 0) | |
247 | return acs_char; | |
248 | ||
664ac93f | 249 | return translate (name, table); |
0bad8af9 TV |
250 | } |
251 | ||
af101512 SC |
252 | /* Update the tui internal configuration according to gdb settings. |
253 | Returns 1 if the configuration has changed and the screen should | |
254 | be redrawn. */ | |
87d557ae TT |
255 | bool |
256 | tui_update_variables () | |
af101512 | 257 | { |
87d557ae | 258 | bool need_redraw = false; |
664ac93f | 259 | int val; |
af101512 | 260 | |
664ac93f TV |
261 | val = translate (tui_border_mode, tui_border_mode_translate); |
262 | need_redraw |= assign_return_if_changed<int> (tui_border_attrs, val); | |
ba769bb0 | 263 | |
664ac93f TV |
264 | val = translate (tui_active_border_mode, tui_border_mode_translate); |
265 | need_redraw |= assign_return_if_changed<int> (tui_active_border_attrs, val); | |
af101512 | 266 | |
0bad8af9 TV |
267 | /* If one corner changes, all characters are changed. Only check the first |
268 | one. */ | |
664ac93f TV |
269 | val = translate_acs (tui_border_kind, tui_border_kind_translate_corner, |
270 | ACS_LRCORNER); | |
ba769bb0 TV |
271 | need_redraw |= assign_return_if_changed<chtype> (tui_border_lrcorner, val); |
272 | ||
0bad8af9 | 273 | tui_border_llcorner |
275cef13 | 274 | = translate_acs (tui_border_kind, tui_border_kind_translate_corner, |
0bad8af9 | 275 | ACS_LLCORNER); |
af101512 | 276 | |
0bad8af9 | 277 | tui_border_ulcorner |
275cef13 | 278 | = translate_acs (tui_border_kind, tui_border_kind_translate_corner, |
0bad8af9 | 279 | ACS_ULCORNER); |
af101512 | 280 | |
0bad8af9 | 281 | tui_border_urcorner = |
275cef13 | 282 | translate_acs (tui_border_kind, tui_border_kind_translate_corner, |
0bad8af9 | 283 | ACS_URCORNER); |
af101512 | 284 | |
0bad8af9 TV |
285 | tui_border_hline |
286 | = translate_acs (tui_border_kind, tui_border_kind_translate_hline, | |
287 | ACS_HLINE); | |
af101512 | 288 | |
0bad8af9 TV |
289 | tui_border_vline |
290 | = translate_acs (tui_border_kind, tui_border_kind_translate_vline, | |
291 | ACS_VLINE); | |
af101512 SC |
292 | |
293 | return need_redraw; | |
294 | } | |
295 | ||
10f59415 SC |
296 | static struct cmd_list_element *tuilist; |
297 | ||
10f59415 | 298 | struct cmd_list_element ** |
da745b36 | 299 | tui_get_cmd_list (void) |
10f59415 SC |
300 | { |
301 | if (tuilist == 0) | |
0743fc83 TT |
302 | add_basic_prefix_cmd ("tui", class_tui, |
303 | _("Text User Interface commands."), | |
2f822da5 | 304 | &tuilist, 0, &cmdlist); |
10f59415 SC |
305 | return &tuilist; |
306 | } | |
307 | ||
6cdb25f4 EZ |
308 | /* The set_func hook of "set tui ..." commands that affect the window |
309 | borders on the TUI display. */ | |
3b5c1d49 SM |
310 | |
311 | static void | |
eb4c3f4a TT |
312 | tui_set_var_cmd (const char *null_args, |
313 | int from_tty, struct cmd_list_element *c) | |
6cdb25f4 EZ |
314 | { |
315 | if (tui_update_variables () && tui_active) | |
316 | tui_rehighlight_all (); | |
317 | } | |
318 | ||
45e42163 TT |
319 | \f |
320 | ||
321 | /* True if TUI resizes should print a message. This is used by the | |
322 | test suite. */ | |
323 | ||
324 | static bool resize_message; | |
325 | ||
326 | static void | |
327 | show_tui_resize_message (struct ui_file *file, int from_tty, | |
328 | struct cmd_list_element *c, const char *value) | |
329 | { | |
6cb06a8c | 330 | gdb_printf (file, _("TUI resize messaging is %s.\n"), value); |
45e42163 TT |
331 | } |
332 | ||
333 | \f | |
334 | ||
97605e61 | 335 | /* Generic window name completion function. Complete window name pointed |
6db98f02 AB |
336 | to by TEXT and WORD. |
337 | ||
338 | If EXCLUDE_CANNOT_FOCUS_P is true, then windows that can't take focus | |
339 | will be excluded from the completions, otherwise they will be included. | |
340 | ||
341 | If INCLUDE_NEXT_PREV_P is true then the special window names 'next' and | |
342 | 'prev' will also be considered as possible completions of the window | |
343 | name. This is independent of EXCLUDE_CANNOT_FOCUS_P. */ | |
2e52ae68 | 344 | |
eb3ff9a5 PA |
345 | static void |
346 | window_name_completer (completion_tracker &tracker, | |
6db98f02 AB |
347 | bool include_next_prev_p, |
348 | bool exclude_cannot_focus_p, | |
97605e61 | 349 | const char *text, const char *word) |
2e52ae68 | 350 | { |
625ad440 | 351 | std::vector<const char *> completion_name_vec; |
2e52ae68 | 352 | |
1ce3e844 | 353 | for (tui_win_info *win_info : all_tui_windows ()) |
2e52ae68 PP |
354 | { |
355 | const char *completion_name = NULL; | |
356 | ||
6db98f02 | 357 | /* Don't include an invisible window. */ |
2d83e710 | 358 | if (!win_info->is_visible ()) |
2e52ae68 PP |
359 | continue; |
360 | ||
6db98f02 AB |
361 | /* If requested, exclude windows that can't be focused. */ |
362 | if (exclude_cannot_focus_p && !win_info->can_focus ()) | |
363 | continue; | |
364 | ||
1ce3e844 | 365 | completion_name = win_info->name (); |
150375dc | 366 | gdb_assert (completion_name != NULL); |
625ad440 | 367 | completion_name_vec.push_back (completion_name); |
2e52ae68 PP |
368 | } |
369 | ||
370 | /* If no windows are considered visible then the TUI has not yet been | |
371 | initialized. But still "focus src" and "focus cmd" will work because | |
372 | invoking the focus command will entail initializing the TUI which sets the | |
416eb92d | 373 | default layout to "src". */ |
625ad440 | 374 | if (completion_name_vec.empty ()) |
2e52ae68 | 375 | { |
625ad440 SM |
376 | completion_name_vec.push_back (SRC_NAME); |
377 | completion_name_vec.push_back (CMD_NAME); | |
2e52ae68 PP |
378 | } |
379 | ||
97605e61 AB |
380 | if (include_next_prev_p) |
381 | { | |
625ad440 SM |
382 | completion_name_vec.push_back ("next"); |
383 | completion_name_vec.push_back ("prev"); | |
97605e61 | 384 | } |
2e52ae68 | 385 | |
2e52ae68 | 386 | |
625ad440 SM |
387 | completion_name_vec.push_back (NULL); |
388 | complete_on_enum (tracker, completion_name_vec.data (), text, word); | |
2e52ae68 PP |
389 | } |
390 | ||
97605e61 AB |
391 | /* Complete possible window names to focus on. TEXT is the complete text |
392 | entered so far, WORD is the word currently being completed. */ | |
393 | ||
eb3ff9a5 | 394 | static void |
97605e61 | 395 | focus_completer (struct cmd_list_element *ignore, |
eb3ff9a5 PA |
396 | completion_tracker &tracker, |
397 | const char *text, const char *word) | |
97605e61 | 398 | { |
6db98f02 | 399 | window_name_completer (tracker, true, true, text, word); |
97605e61 AB |
400 | } |
401 | ||
402 | /* Complete possible window names for winheight command. TEXT is the | |
403 | complete text entered so far, WORD is the word currently being | |
404 | completed. */ | |
405 | ||
eb3ff9a5 | 406 | static void |
97605e61 | 407 | winheight_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 408 | completion_tracker &tracker, |
97605e61 AB |
409 | const char *text, const char *word) |
410 | { | |
411 | /* The first word is the window name. That we can complete. Subsequent | |
412 | words can't be completed. */ | |
413 | if (word != text) | |
eb3ff9a5 | 414 | return; |
97605e61 | 415 | |
6db98f02 | 416 | window_name_completer (tracker, false, false, text, word); |
97605e61 AB |
417 | } |
418 | ||
3e752b04 SC |
419 | /* Update gdb's knowledge of the terminal size. */ |
420 | void | |
d02c80cd | 421 | tui_update_gdb_sizes (void) |
3e752b04 | 422 | { |
d6e5e7f7 PP |
423 | int width, height; |
424 | ||
425 | if (tui_active) | |
426 | { | |
cb2ce893 TT |
427 | width = TUI_CMD_WIN->width; |
428 | height = TUI_CMD_WIN->height; | |
d6e5e7f7 PP |
429 | } |
430 | else | |
431 | { | |
432 | width = tui_term_width (); | |
433 | height = tui_term_height (); | |
434 | } | |
435 | ||
436 | set_screen_width_and_height (width, height); | |
3e752b04 SC |
437 | } |
438 | ||
c906108c | 439 | |
c906108c | 440 | void |
13446e05 | 441 | tui_win_info::forward_scroll (int num_to_scroll) |
c906108c | 442 | { |
13446e05 | 443 | if (num_to_scroll == 0) |
cb2ce893 | 444 | num_to_scroll = height - 3; |
c906108c | 445 | |
c3bd716f | 446 | do_scroll_vertical (num_to_scroll); |
a21fcd8f | 447 | } |
c906108c | 448 | |
c906108c | 449 | void |
13446e05 | 450 | tui_win_info::backward_scroll (int num_to_scroll) |
c906108c | 451 | { |
13446e05 | 452 | if (num_to_scroll == 0) |
cb2ce893 | 453 | num_to_scroll = height - 3; |
13446e05 | 454 | |
c3bd716f | 455 | do_scroll_vertical (-num_to_scroll); |
a21fcd8f | 456 | } |
c906108c SS |
457 | |
458 | ||
c906108c | 459 | void |
13446e05 | 460 | tui_win_info::left_scroll (int num_to_scroll) |
c906108c | 461 | { |
13446e05 TT |
462 | if (num_to_scroll == 0) |
463 | num_to_scroll = 1; | |
464 | ||
c3bd716f | 465 | do_scroll_horizontal (num_to_scroll); |
a21fcd8f | 466 | } |
c906108c SS |
467 | |
468 | ||
c906108c | 469 | void |
13446e05 | 470 | tui_win_info::right_scroll (int num_to_scroll) |
c906108c | 471 | { |
13446e05 TT |
472 | if (num_to_scroll == 0) |
473 | num_to_scroll = 1; | |
474 | ||
c3bd716f | 475 | do_scroll_horizontal (-num_to_scroll); |
e8b915dc | 476 | } |
c906108c SS |
477 | |
478 | ||
c906108c | 479 | void |
a21fcd8f | 480 | tui_refresh_all_win (void) |
c906108c | 481 | { |
3e266828 | 482 | clearok (curscr, TRUE); |
1ce3e844 | 483 | tui_refresh_all (); |
bc712bbf | 484 | } |
c906108c | 485 | |
6cdb25f4 EZ |
486 | void |
487 | tui_rehighlight_all (void) | |
488 | { | |
1ce3e844 | 489 | for (tui_win_info *win_info : all_tui_windows ()) |
b4ef5aeb | 490 | win_info->check_and_display_highlight_if_needed (); |
6cdb25f4 | 491 | } |
c906108c | 492 | |
b021a221 | 493 | /* Resize all the windows based on the terminal size. This function |
ae2b5380 | 494 | gets called from within the readline SIGWINCH handler. */ |
c906108c | 495 | void |
6ba8e26f | 496 | tui_resize_all (void) |
c906108c | 497 | { |
6ba8e26f | 498 | int height_diff, width_diff; |
9255ee31 | 499 | int screenheight, screenwidth; |
c906108c | 500 | |
9255ee31 | 501 | rl_get_screen_size (&screenheight, &screenwidth); |
deb1ba4e TV |
502 | screenwidth += readline_hidden_cols; |
503 | ||
6ba8e26f AC |
504 | width_diff = screenwidth - tui_term_width (); |
505 | height_diff = screenheight - tui_term_height (); | |
506 | if (height_diff || width_diff) | |
c906108c | 507 | { |
10f59415 SC |
508 | #ifdef HAVE_RESIZE_TERM |
509 | resize_term (screenheight, screenwidth); | |
510 | #endif | |
1cc6d956 | 511 | /* Turn keypad off while we resize. */ |
82a5082e | 512 | keypad (TUI_CMD_WIN->handle.get (), FALSE); |
3e752b04 | 513 | tui_update_gdb_sizes (); |
dd1abb8c AC |
514 | tui_set_term_height_to (screenheight); |
515 | tui_set_term_width_to (screenwidth); | |
3d979945 | 516 | |
c366c1f0 | 517 | /* erase + clearok are used instead of a straightforward clear as |
dda83cd7 | 518 | AIX 5.3 does not define clear. */ |
c366c1f0 TT |
519 | erase (); |
520 | clearok (curscr, TRUE); | |
51b72f73 AB |
521 | /* Apply the current layout. The 'false' here allows the command |
522 | window to resize proportionately with containing terminal, rather | |
523 | than maintaining a fixed size. */ | |
524 | tui_apply_current_layout (false); /* Turn keypad back on. */ | |
82a5082e | 525 | keypad (TUI_CMD_WIN->handle.get (), TRUE); |
c906108c | 526 | } |
6ba8e26f | 527 | } |
c906108c | 528 | |
2c0b251b | 529 | #ifdef SIGWINCH |
c4ef48c6 PP |
530 | /* Token for use by TUI's asynchronous SIGWINCH handler. */ |
531 | static struct async_signal_handler *tui_sigwinch_token; | |
532 | ||
533 | /* TUI's SIGWINCH signal handler. */ | |
2c0b251b | 534 | static void |
6ba8e26f | 535 | tui_sigwinch_handler (int signal) |
c906108c | 536 | { |
c4ef48c6 | 537 | mark_async_signal_handler (tui_sigwinch_token); |
9abd8a65 | 538 | tui_set_win_resized_to (true); |
6ba8e26f | 539 | } |
c4ef48c6 PP |
540 | |
541 | /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */ | |
542 | static void | |
543 | tui_async_resize_screen (gdb_client_data arg) | |
544 | { | |
a88d0bb3 PP |
545 | rl_resize_terminal (); |
546 | ||
c4ef48c6 | 547 | if (!tui_active) |
a88d0bb3 PP |
548 | { |
549 | int screen_height, screen_width; | |
c4ef48c6 | 550 | |
a88d0bb3 | 551 | rl_get_screen_size (&screen_height, &screen_width); |
deb1ba4e | 552 | screen_width += readline_hidden_cols; |
a88d0bb3 PP |
553 | set_screen_width_and_height (screen_width, screen_height); |
554 | ||
555 | /* win_resized is left set so that the next call to tui_enable() | |
556 | resizes the TUI windows. */ | |
557 | } | |
558 | else | |
559 | { | |
9abd8a65 | 560 | tui_set_win_resized_to (false); |
a88d0bb3 PP |
561 | tui_resize_all (); |
562 | tui_refresh_all_win (); | |
563 | tui_update_gdb_sizes (); | |
45e42163 TT |
564 | if (resize_message) |
565 | { | |
566 | static int count; | |
567 | printf_unfiltered ("@@ resize done %d, size = %dx%d\n", count, | |
568 | tui_term_width (), tui_term_height ()); | |
569 | ++count; | |
570 | } | |
a88d0bb3 PP |
571 | tui_redisplay_readline (); |
572 | } | |
c4ef48c6 | 573 | } |
2c0b251b | 574 | #endif |
c906108c | 575 | |
c4ef48c6 PP |
576 | /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not |
577 | uninstalled when we exit TUI, so the handler should not assume that TUI is | |
578 | always active. */ | |
9612b5ec UW |
579 | void |
580 | tui_initialize_win (void) | |
581 | { | |
582 | #ifdef SIGWINCH | |
c4ef48c6 | 583 | tui_sigwinch_token |
db20ebdf SM |
584 | = create_async_signal_handler (tui_async_resize_screen, NULL, |
585 | "tui-sigwinch"); | |
c4ef48c6 PP |
586 | |
587 | { | |
9612b5ec | 588 | #ifdef HAVE_SIGACTION |
c4ef48c6 | 589 | struct sigaction old_winch; |
1c5313c5 | 590 | |
c4ef48c6 PP |
591 | memset (&old_winch, 0, sizeof (old_winch)); |
592 | old_winch.sa_handler = &tui_sigwinch_handler; | |
a344fc09 | 593 | #ifdef SA_RESTART |
c4ef48c6 | 594 | old_winch.sa_flags = SA_RESTART; |
a344fc09 | 595 | #endif |
c4ef48c6 | 596 | sigaction (SIGWINCH, &old_winch, NULL); |
9612b5ec | 597 | #else |
c4ef48c6 | 598 | signal (SIGWINCH, &tui_sigwinch_handler); |
9612b5ec | 599 | #endif |
c4ef48c6 | 600 | } |
9612b5ec UW |
601 | #endif |
602 | } | |
c906108c SS |
603 | |
604 | ||
c906108c | 605 | static void |
0b39b52e | 606 | tui_scroll_forward_command (const char *arg, int from_tty) |
c906108c | 607 | { |
6ba8e26f | 608 | int num_to_scroll = 1; |
5b6fe301 | 609 | struct tui_win_info *win_to_scroll; |
c906108c | 610 | |
1854bb21 SC |
611 | /* Make sure the curses mode is enabled. */ |
612 | tui_enable (); | |
63a33118 | 613 | if (arg == NULL) |
cafb3438 | 614 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
c906108c | 615 | else |
6ba8e26f | 616 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 617 | win_to_scroll->forward_scroll (num_to_scroll); |
e8b915dc | 618 | } |
c906108c SS |
619 | |
620 | ||
c906108c | 621 | static void |
0b39b52e | 622 | tui_scroll_backward_command (const char *arg, int from_tty) |
c906108c | 623 | { |
6ba8e26f | 624 | int num_to_scroll = 1; |
5b6fe301 | 625 | struct tui_win_info *win_to_scroll; |
c906108c | 626 | |
1854bb21 SC |
627 | /* Make sure the curses mode is enabled. */ |
628 | tui_enable (); | |
63a33118 | 629 | if (arg == NULL) |
cafb3438 | 630 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
c906108c | 631 | else |
6ba8e26f | 632 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 633 | win_to_scroll->backward_scroll (num_to_scroll); |
e8b915dc | 634 | } |
c906108c SS |
635 | |
636 | ||
c906108c | 637 | static void |
0b39b52e | 638 | tui_scroll_left_command (const char *arg, int from_tty) |
c906108c | 639 | { |
6ba8e26f | 640 | int num_to_scroll; |
5b6fe301 | 641 | struct tui_win_info *win_to_scroll; |
c906108c | 642 | |
1854bb21 SC |
643 | /* Make sure the curses mode is enabled. */ |
644 | tui_enable (); | |
6ba8e26f | 645 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 646 | win_to_scroll->left_scroll (num_to_scroll); |
e8b915dc | 647 | } |
c906108c SS |
648 | |
649 | ||
c906108c | 650 | static void |
0b39b52e | 651 | tui_scroll_right_command (const char *arg, int from_tty) |
c906108c | 652 | { |
6ba8e26f | 653 | int num_to_scroll; |
5b6fe301 | 654 | struct tui_win_info *win_to_scroll; |
c906108c | 655 | |
1854bb21 SC |
656 | /* Make sure the curses mode is enabled. */ |
657 | tui_enable (); | |
6ba8e26f | 658 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 659 | win_to_scroll->right_scroll (num_to_scroll); |
e8b915dc | 660 | } |
c906108c SS |
661 | |
662 | ||
9f6ad286 TT |
663 | /* Answer the window represented by name. */ |
664 | static struct tui_win_info * | |
8082468f | 665 | tui_partial_win_by_name (std::string_view name) |
9f6ad286 | 666 | { |
e098d18c TT |
667 | struct tui_win_info *best = nullptr; |
668 | ||
947f7597 | 669 | for (tui_win_info *item : all_tui_windows ()) |
9f6ad286 | 670 | { |
947f7597 TV |
671 | const char *cur_name = item->name (); |
672 | ||
673 | if (name == cur_name) | |
674 | return item; | |
675 | if (startswith (cur_name, name)) | |
9f6ad286 | 676 | { |
947f7597 TV |
677 | if (best != nullptr) |
678 | error (_("Window name \"%*s\" is ambiguous"), | |
679 | (int) name.size (), name.data ()); | |
680 | best = item; | |
9f6ad286 TT |
681 | } |
682 | } | |
683 | ||
e098d18c | 684 | return best; |
9f6ad286 TT |
685 | } |
686 | ||
6ba8e26f | 687 | /* Set focus to the window named by 'arg'. */ |
c906108c | 688 | static void |
01aeb396 | 689 | tui_set_focus_command (const char *arg, int from_tty) |
c906108c | 690 | { |
01aeb396 TT |
691 | tui_enable (); |
692 | ||
ca793b96 TT |
693 | if (arg == NULL) |
694 | error_no_arg (_("name of window to focus")); | |
c906108c | 695 | |
ca793b96 | 696 | struct tui_win_info *win_info = NULL; |
c906108c | 697 | |
c5739418 | 698 | if (startswith ("next", arg)) |
ca793b96 | 699 | win_info = tui_next_win (tui_win_with_focus ()); |
c5739418 | 700 | else if (startswith ("prev", arg)) |
ca793b96 | 701 | win_info = tui_prev_win (tui_win_with_focus ()); |
c906108c | 702 | else |
ca793b96 TT |
703 | win_info = tui_partial_win_by_name (arg); |
704 | ||
58c6d2ac AB |
705 | if (win_info == nullptr) |
706 | { | |
707 | /* When WIN_INFO is nullptr this can either mean that the window name | |
708 | is unknown to GDB, or that the window is not in the current | |
709 | layout. To try and help the user, give a different error | |
710 | depending on which of these is the case. */ | |
711 | std::string matching_window_name; | |
712 | bool is_ambiguous = false; | |
713 | ||
714 | for (const std::string &name : all_known_window_names ()) | |
715 | { | |
716 | /* Look through all windows in the current layout, if the window | |
717 | is in the current layout then we're not interested is it. */ | |
718 | for (tui_win_info *item : all_tui_windows ()) | |
719 | if (item->name () == name) | |
720 | continue; | |
721 | ||
722 | if (startswith (name, arg)) | |
723 | { | |
724 | if (matching_window_name.empty ()) | |
725 | matching_window_name = name; | |
726 | else | |
727 | is_ambiguous = true; | |
728 | } | |
729 | }; | |
730 | ||
731 | if (!matching_window_name.empty ()) | |
732 | { | |
733 | if (is_ambiguous) | |
734 | error (_("No windows matching \"%s\" in the current layout"), | |
735 | arg); | |
736 | else | |
737 | error (_("Window \"%s\" is not in the current layout"), | |
738 | matching_window_name.c_str ()); | |
739 | } | |
740 | else | |
741 | error (_("Unrecognized window name \"%s\""), arg); | |
742 | } | |
6789344a AB |
743 | |
744 | /* If a window is part of the current layout then it will have a | |
745 | tui_win_info associated with it and be visible, otherwise, there will | |
746 | be no tui_win_info and the above error will have been raised. */ | |
747 | gdb_assert (win_info->is_visible ()); | |
ca793b96 | 748 | |
24f3aded AB |
749 | if (!win_info->can_focus ()) |
750 | error (_("Window \"%s\" cannot be focused"), arg); | |
751 | ||
ca793b96 | 752 | tui_set_win_focus_to (win_info); |
6cb06a8c TT |
753 | gdb_printf (_("Focus set to %s window.\n"), |
754 | tui_win_with_focus ()->name ()); | |
6ba8e26f | 755 | } |
c906108c | 756 | |
c906108c | 757 | static void |
1d12d88f | 758 | tui_all_windows_info (const char *arg, int from_tty) |
c906108c | 759 | { |
82e3b564 TT |
760 | if (!tui_active) |
761 | { | |
6cb06a8c | 762 | gdb_printf (_("The TUI is not active.\n")); |
82e3b564 TT |
763 | return; |
764 | } | |
765 | ||
5b6fe301 | 766 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
25a2915e TT |
767 | struct ui_out *uiout = current_uiout; |
768 | ||
f62843d7 | 769 | ui_out_emit_table table_emitter (uiout, 4, -1, "tui-windows"); |
25a2915e TT |
770 | uiout->table_header (10, ui_left, "name", "Name"); |
771 | uiout->table_header (5, ui_right, "lines", "Lines"); | |
f62843d7 | 772 | uiout->table_header (7, ui_right, "columns", "Columns"); |
25a2915e TT |
773 | uiout->table_header (10, ui_left, "focus", "Focus"); |
774 | uiout->table_body (); | |
c906108c | 775 | |
1ce3e844 | 776 | for (tui_win_info *win_info : all_tui_windows ()) |
2d83e710 | 777 | if (win_info->is_visible ()) |
c906108c | 778 | { |
25a2915e TT |
779 | ui_out_emit_tuple tuple_emitter (uiout, nullptr); |
780 | ||
781 | uiout->field_string ("name", win_info->name ()); | |
782 | uiout->field_signed ("lines", win_info->height); | |
f62843d7 | 783 | uiout->field_signed ("columns", win_info->width); |
1ce3e844 | 784 | if (win_with_focus == win_info) |
25a2915e | 785 | uiout->field_string ("focus", _("(has focus)")); |
c906108c | 786 | else |
25a2915e TT |
787 | uiout->field_skip ("focus"); |
788 | uiout->text ("\n"); | |
c906108c | 789 | } |
6ba8e26f | 790 | } |
c906108c SS |
791 | |
792 | ||
c906108c | 793 | static void |
0b39b52e | 794 | tui_refresh_all_command (const char *arg, int from_tty) |
c906108c | 795 | { |
1854bb21 SC |
796 | /* Make sure the curses mode is enabled. */ |
797 | tui_enable (); | |
798 | ||
a21fcd8f | 799 | tui_refresh_all_win (); |
c906108c SS |
800 | } |
801 | ||
e555083f TT |
802 | #define DEFAULT_TAB_LEN 8 |
803 | ||
7806cea7 TT |
804 | /* The tab width that should be used by the TUI. */ |
805 | ||
806 | unsigned int tui_tab_width = DEFAULT_TAB_LEN; | |
807 | ||
808 | /* The tab width as set by the user. */ | |
809 | ||
810 | static unsigned int internal_tab_width = DEFAULT_TAB_LEN; | |
811 | ||
d83f1fe6 TT |
812 | /* After the tab width is set, call this to update the relevant |
813 | windows. */ | |
814 | ||
815 | static void | |
816 | update_tab_width () | |
817 | { | |
1ce3e844 | 818 | for (tui_win_info *win_info : all_tui_windows ()) |
7806cea7 | 819 | { |
2d83e710 | 820 | if (win_info->is_visible ()) |
1ce3e844 | 821 | win_info->update_tab_width (); |
7806cea7 TT |
822 | } |
823 | } | |
824 | ||
825 | /* Callback for "set tui tab-width". */ | |
826 | ||
827 | static void | |
828 | tui_set_tab_width (const char *ignore, | |
829 | int from_tty, struct cmd_list_element *c) | |
830 | { | |
831 | if (internal_tab_width == 0) | |
832 | { | |
833 | internal_tab_width = tui_tab_width; | |
834 | error (_("Tab width must not be 0")); | |
835 | } | |
836 | ||
837 | tui_tab_width = internal_tab_width; | |
838 | update_tab_width (); | |
839 | } | |
840 | ||
841 | /* Callback for "show tui tab-width". */ | |
842 | ||
843 | static void | |
844 | tui_show_tab_width (struct ui_file *file, int from_tty, | |
845 | struct cmd_list_element *c, const char *value) | |
846 | { | |
6cb06a8c | 847 | gdb_printf (file, _("TUI tab width is %s spaces.\n"), value); |
7806cea7 TT |
848 | |
849 | } | |
c906108c | 850 | |
d1da6b01 TT |
851 | /* See tui-win.h. */ |
852 | ||
853 | bool compact_source = false; | |
854 | ||
855 | /* Callback for "set tui compact-source". */ | |
856 | ||
857 | static void | |
858 | tui_set_compact_source (const char *ignore, int from_tty, | |
859 | struct cmd_list_element *c) | |
860 | { | |
861 | if (TUI_SRC_WIN != nullptr) | |
862 | TUI_SRC_WIN->refill (); | |
863 | } | |
864 | ||
865 | /* Callback for "show tui compact-source". */ | |
866 | ||
867 | static void | |
868 | tui_show_compact_source (struct ui_file *file, int from_tty, | |
869 | struct cmd_list_element *c, const char *value) | |
870 | { | |
6cb06a8c | 871 | gdb_printf (file, _("TUI source window compactness is %s.\n"), value); |
d1da6b01 TT |
872 | } |
873 | ||
0f6a6994 MG |
874 | bool tui_enable_mouse = true; |
875 | ||
876 | /* Implement 'show tui mouse-events'. */ | |
877 | ||
878 | static void | |
879 | show_tui_mouse_events (struct ui_file *file, int from_tty, | |
880 | struct cmd_list_element *c, const char *value) | |
881 | { | |
882 | gdb_printf (file, _("TUI mouse events are %s.\n"), value); | |
883 | } | |
884 | ||
c54da50d | 885 | /* Set the tab width of the specified window. */ |
c906108c | 886 | static void |
0b39b52e | 887 | tui_set_tab_width_command (const char *arg, int from_tty) |
c906108c | 888 | { |
1854bb21 SC |
889 | /* Make sure the curses mode is enabled. */ |
890 | tui_enable (); | |
63a33118 | 891 | if (arg != NULL) |
c906108c SS |
892 | { |
893 | int ts; | |
894 | ||
895 | ts = atoi (arg); | |
7806cea7 TT |
896 | if (ts <= 0) |
897 | warning (_("Tab widths greater than 0 must be specified.")); | |
898 | else | |
cb86fcc1 | 899 | { |
7806cea7 TT |
900 | internal_tab_width = ts; |
901 | tui_tab_width = ts; | |
902 | ||
903 | update_tab_width (); | |
cb86fcc1 | 904 | } |
c906108c | 905 | } |
6ba8e26f | 906 | } |
c906108c | 907 | |
160444ec AB |
908 | /* Helper function for the user commands to adjust a window's width or |
909 | height. The ARG string contains the command line arguments from the | |
910 | user, which should give the name of a window, and how to adjust the | |
911 | size. | |
912 | ||
913 | When SET_WIDTH_P is true the width of the window is adjusted based on | |
914 | ARG, and when SET_WIDTH_P is false, the height of the window is adjusted | |
915 | based on ARG. | |
916 | ||
917 | On invalid input, or if the size can't be adjusted as requested, then an | |
918 | error is thrown, otherwise, the window sizes are adjusted, and the | |
919 | windows redrawn. */ | |
c906108c | 920 | |
c906108c | 921 | static void |
160444ec | 922 | tui_set_win_size (const char *arg, bool set_width_p) |
c906108c | 923 | { |
1854bb21 SC |
924 | /* Make sure the curses mode is enabled. */ |
925 | tui_enable (); | |
ca793b96 TT |
926 | if (arg == NULL) |
927 | error_no_arg (_("name of window")); | |
c906108c | 928 | |
ca793b96 TT |
929 | const char *buf = arg; |
930 | const char *buf_ptr = buf; | |
160444ec | 931 | int new_size; |
ca793b96 | 932 | struct tui_win_info *win_info; |
c906108c | 933 | |
ca793b96 | 934 | buf_ptr = skip_to_space (buf_ptr); |
78e8cb91 | 935 | |
ca793b96 | 936 | /* Validate the window name. */ |
8082468f | 937 | std::string_view wname (buf, buf_ptr - buf); |
ca793b96 | 938 | win_info = tui_partial_win_by_name (wname); |
78e8cb91 | 939 | |
ca793b96 TT |
940 | if (win_info == NULL) |
941 | error (_("Unrecognized window name \"%s\""), arg); | |
942 | if (!win_info->is_visible ()) | |
943 | error (_("Window \"%s\" is not visible"), arg); | |
944 | ||
945 | /* Process the size. */ | |
946 | buf_ptr = skip_spaces (buf_ptr); | |
947 | ||
948 | if (*buf_ptr != '\0') | |
949 | { | |
950 | bool negate = false; | |
951 | bool fixed_size = true; | |
952 | int input_no;; | |
953 | ||
954 | if (*buf_ptr == '+' || *buf_ptr == '-') | |
955 | { | |
956 | if (*buf_ptr == '-') | |
957 | negate = true; | |
958 | fixed_size = false; | |
959 | buf_ptr++; | |
960 | } | |
961 | input_no = atoi (buf_ptr); | |
962 | if (input_no > 0) | |
963 | { | |
964 | if (negate) | |
965 | input_no *= (-1); | |
966 | if (fixed_size) | |
160444ec | 967 | new_size = input_no; |
ca793b96 | 968 | else |
160444ec AB |
969 | { |
970 | int curr_size; | |
971 | if (set_width_p) | |
972 | curr_size = win_info->width; | |
973 | else | |
974 | curr_size = win_info->height; | |
975 | new_size = curr_size + input_no; | |
976 | } | |
ca793b96 TT |
977 | |
978 | /* Now change the window's height, and adjust | |
979 | all other windows around it. */ | |
160444ec AB |
980 | if (set_width_p) |
981 | tui_adjust_window_width (win_info, new_size); | |
982 | else | |
983 | tui_adjust_window_height (win_info, new_size); | |
ca793b96 | 984 | tui_update_gdb_sizes (); |
c906108c SS |
985 | } |
986 | else | |
160444ec AB |
987 | { |
988 | if (set_width_p) | |
989 | error (_("Invalid window width specified")); | |
990 | else | |
991 | error (_("Invalid window height specified")); | |
992 | } | |
c906108c | 993 | } |
6ba8e26f | 994 | } |
c906108c | 995 | |
160444ec AB |
996 | /* Implement the 'tui window height' command (alias 'winheight'). */ |
997 | ||
998 | static void | |
999 | tui_set_win_height_command (const char *arg, int from_tty) | |
1000 | { | |
1001 | /* Pass false as the final argument to set the height. */ | |
1002 | tui_set_win_size (arg, false); | |
1003 | } | |
1004 | ||
1005 | /* Implement the 'tui window width' command (alias 'winwidth'). */ | |
1006 | ||
1007 | static void | |
1008 | tui_set_win_width_command (const char *arg, int from_tty) | |
1009 | { | |
1010 | /* Pass true as the final argument to set the width. */ | |
1011 | tui_set_win_size (arg, true); | |
1012 | } | |
1013 | ||
5fcee43a | 1014 | /* See tui-data.h. */ |
c906108c | 1015 | |
8903bd8a TT |
1016 | int |
1017 | tui_win_info::max_height () const | |
1018 | { | |
b45b7407 | 1019 | return tui_term_height (); |
8903bd8a TT |
1020 | } |
1021 | ||
7c043ba6 TT |
1022 | /* See tui-data.h. */ |
1023 | ||
1024 | int | |
32c1e210 | 1025 | tui_win_info::max_width () const |
7c043ba6 | 1026 | { |
b45b7407 | 1027 | return tui_term_width (); |
7c043ba6 TT |
1028 | } |
1029 | ||
c906108c | 1030 | static void |
0b39b52e | 1031 | parse_scrolling_args (const char *arg, |
08ef48c5 | 1032 | struct tui_win_info **win_to_scroll, |
6ba8e26f | 1033 | int *num_to_scroll) |
c906108c | 1034 | { |
6ba8e26f AC |
1035 | if (num_to_scroll) |
1036 | *num_to_scroll = 0; | |
1037 | *win_to_scroll = tui_win_with_focus (); | |
c906108c | 1038 | |
ef5eab5a MS |
1039 | /* First set up the default window to scroll, in case there is no |
1040 | window name arg. */ | |
63a33118 | 1041 | if (arg != NULL) |
c906108c | 1042 | { |
f71c8822 | 1043 | char *buf_ptr; |
c906108c | 1044 | |
1cc6d956 | 1045 | /* Process the number of lines to scroll. */ |
f71c8822 TT |
1046 | std::string copy = arg; |
1047 | buf_ptr = ©[0]; | |
6ba8e26f | 1048 | if (isdigit (*buf_ptr)) |
c906108c | 1049 | { |
6ba8e26f | 1050 | char *num_str; |
c906108c | 1051 | |
6ba8e26f AC |
1052 | num_str = buf_ptr; |
1053 | buf_ptr = strchr (buf_ptr, ' '); | |
63a33118 | 1054 | if (buf_ptr != NULL) |
c906108c | 1055 | { |
78e8cb91 | 1056 | *buf_ptr = '\0'; |
6ba8e26f AC |
1057 | if (num_to_scroll) |
1058 | *num_to_scroll = atoi (num_str); | |
1059 | buf_ptr++; | |
c906108c | 1060 | } |
6ba8e26f AC |
1061 | else if (num_to_scroll) |
1062 | *num_to_scroll = atoi (num_str); | |
c906108c SS |
1063 | } |
1064 | ||
1cc6d956 | 1065 | /* Process the window name if one is specified. */ |
63a33118 | 1066 | if (buf_ptr != NULL) |
c906108c | 1067 | { |
a121b7c1 | 1068 | const char *wname; |
c906108c | 1069 | |
78e8cb91 | 1070 | wname = skip_spaces (buf_ptr); |
c906108c | 1071 | |
78e8cb91 | 1072 | if (*wname != '\0') |
c709a7c2 | 1073 | { |
78e8cb91 TT |
1074 | *win_to_scroll = tui_partial_win_by_name (wname); |
1075 | ||
1076 | if (*win_to_scroll == NULL) | |
1077 | error (_("Unrecognized window `%s'"), wname); | |
1078 | if (!(*win_to_scroll)->is_visible ()) | |
1079 | error (_("Window is not visible")); | |
1080 | else if (*win_to_scroll == TUI_CMD_WIN) | |
1081 | *win_to_scroll = *(tui_source_windows ().begin ()); | |
c709a7c2 | 1082 | } |
c906108c | 1083 | } |
c906108c | 1084 | } |
6ba8e26f | 1085 | } |
7806cea7 | 1086 | |
51c2a9e2 AB |
1087 | /* The list of 'tui window' sub-commands. */ |
1088 | ||
1089 | static cmd_list_element *tui_window_cmds = nullptr; | |
1090 | ||
1091 | /* Called to implement 'tui window'. */ | |
1092 | ||
1093 | static void | |
1094 | tui_window_command (const char *args, int from_tty) | |
1095 | { | |
1096 | help_list (tui_window_cmds, "tui window ", all_commands, gdb_stdout); | |
1097 | } | |
1098 | ||
58b77c6a TV |
1099 | /* See tui-win.h. */ |
1100 | ||
1101 | bool tui_left_margin_verbose = false; | |
1102 | ||
7806cea7 TT |
1103 | /* Function to initialize gdb commands, for tui window |
1104 | manipulation. */ | |
1105 | ||
6c265988 | 1106 | void _initialize_tui_win (); |
7806cea7 | 1107 | void |
6c265988 | 1108 | _initialize_tui_win () |
7806cea7 TT |
1109 | { |
1110 | static struct cmd_list_element *tui_setlist; | |
1111 | static struct cmd_list_element *tui_showlist; | |
7806cea7 TT |
1112 | |
1113 | /* Define the classes of commands. | |
1114 | They will appear in the help list in the reverse of this order. */ | |
f54bdb6d SM |
1115 | add_setshow_prefix_cmd ("tui", class_tui, |
1116 | _("TUI configuration variables."), | |
1117 | _("TUI configuration variables."), | |
1118 | &tui_setlist, &tui_showlist, | |
1119 | &setlist, &showlist); | |
7806cea7 | 1120 | |
51c2a9e2 AB |
1121 | cmd_list_element *refresh_cmd |
1122 | = add_cmd ("refresh", class_tui, tui_refresh_all_command, | |
1123 | _("Refresh the terminal display."), | |
1124 | tui_get_cmd_list ()); | |
1125 | add_com_alias ("refresh", refresh_cmd, class_tui, 0); | |
7806cea7 | 1126 | |
3947f654 SM |
1127 | cmd_list_element *tabset_cmd |
1128 | = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\ | |
7806cea7 | 1129 | Set the width (in characters) of tab stops.\n\ |
89549d7f | 1130 | Usage: tabset N")); |
3947f654 | 1131 | deprecate_cmd (tabset_cmd, "set tui tab-width"); |
7806cea7 | 1132 | |
51c2a9e2 AB |
1133 | /* Setup the 'tui window' list of command. */ |
1134 | add_prefix_cmd ("window", class_tui, tui_window_command, | |
1135 | _("Text User Interface window commands."), | |
1136 | &tui_window_cmds, 1, tui_get_cmd_list ()); | |
1137 | ||
3947f654 | 1138 | cmd_list_element *winheight_cmd |
51c2a9e2 | 1139 | = add_cmd ("height", class_tui, tui_set_win_height_command, _("\ |
ca793b96 | 1140 | Set or modify the height of a specified window.\n\ |
51c2a9e2 AB |
1141 | Usage: tui window height WINDOW-NAME [+ | -] NUM-LINES\n\ |
1142 | Use \"info win\" to see the names of the windows currently being displayed."), | |
1143 | &tui_window_cmds); | |
1144 | add_com_alias ("winheight", winheight_cmd, class_tui, 0); | |
3947f654 SM |
1145 | add_com_alias ("wh", winheight_cmd, class_tui, 0); |
1146 | set_cmd_completer (winheight_cmd, winheight_completer); | |
160444ec AB |
1147 | |
1148 | cmd_list_element *winwidth_cmd | |
1149 | = add_cmd ("width", class_tui, tui_set_win_width_command, _("\ | |
1150 | Set or modify the width of a specified window.\n\ | |
1151 | Usage: tui window width WINDOW-NAME [+ | -] NUM-LINES\n\ | |
1152 | Use \"info win\" to see the names of the windows currently being displayed."), | |
1153 | &tui_window_cmds); | |
1154 | add_com_alias ("winwidth", winwidth_cmd, class_tui, 0); | |
1155 | set_cmd_completer (winwidth_cmd, winheight_completer); | |
1156 | ||
7806cea7 | 1157 | add_info ("win", tui_all_windows_info, |
283be8bf TT |
1158 | _("List of all displayed windows.\n\ |
1159 | Usage: info win")); | |
3947f654 | 1160 | cmd_list_element *focus_cmd |
51c2a9e2 | 1161 | = add_cmd ("focus", class_tui, tui_set_focus_command, _("\ |
ca793b96 | 1162 | Set focus to named window or next/prev window.\n\ |
51c2a9e2 AB |
1163 | Usage: tui focus [WINDOW-NAME | next | prev]\n\ |
1164 | Use \"info win\" to see the names of the windows currently being displayed."), | |
1165 | tui_get_cmd_list ()); | |
1166 | add_com_alias ("focus", focus_cmd, class_tui, 0); | |
3947f654 SM |
1167 | add_com_alias ("fs", focus_cmd, class_tui, 0); |
1168 | set_cmd_completer (focus_cmd, focus_completer); | |
7806cea7 TT |
1169 | add_com ("+", class_tui, tui_scroll_forward_command, _("\ |
1170 | Scroll window forward.\n\ | |
7a27a45b AB |
1171 | Usage: + [N] [WIN]\n\ |
1172 | Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\ | |
1173 | defaults to 1, and WIN defaults to the currently focused window.")); | |
7806cea7 TT |
1174 | add_com ("-", class_tui, tui_scroll_backward_command, _("\ |
1175 | Scroll window backward.\n\ | |
7a27a45b AB |
1176 | Usage: - [N] [WIN]\n\ |
1177 | Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\ | |
1178 | defaults to 1, and WIN defaults to the currently focused window.")); | |
7806cea7 TT |
1179 | add_com ("<", class_tui, tui_scroll_left_command, _("\ |
1180 | Scroll window text to the left.\n\ | |
7a27a45b AB |
1181 | Usage: < [N] [WIN]\n\ |
1182 | Scroll window WIN N characters left. Both WIN and N are optional, N\n\ | |
1183 | defaults to 1, and WIN defaults to the currently focused window.")); | |
7806cea7 TT |
1184 | add_com (">", class_tui, tui_scroll_right_command, _("\ |
1185 | Scroll window text to the right.\n\ | |
7a27a45b AB |
1186 | Usage: > [N] [WIN]\n\ |
1187 | Scroll window WIN N characters right. Both WIN and N are optional, N\n\ | |
1188 | defaults to 1, and WIN defaults to the currently focused window.")); | |
7806cea7 TT |
1189 | |
1190 | /* Define the tui control variables. */ | |
1191 | add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums, | |
1192 | &tui_border_kind, _("\ | |
1193 | Set the kind of border for TUI windows."), _("\ | |
1194 | Show the kind of border for TUI windows."), _("\ | |
1195 | This variable controls the border of TUI windows:\n\ | |
89549d7f TT |
1196 | space use a white space\n\ |
1197 | ascii use ascii characters + - | for the border\n\ | |
1198 | acs use the Alternate Character Set"), | |
7806cea7 TT |
1199 | tui_set_var_cmd, |
1200 | show_tui_border_kind, | |
1201 | &tui_setlist, &tui_showlist); | |
1202 | ||
45601fb8 | 1203 | const std::string help_attribute_mode (_("\ |
89549d7f TT |
1204 | normal normal display\n\ |
1205 | standout use highlight mode of terminal\n\ | |
1206 | reverse use reverse video mode\n\ | |
1207 | half use half bright\n\ | |
1208 | half-standout use half bright and standout mode\n\ | |
1209 | bold use extra bright or bold\n\ | |
45601fb8 TV |
1210 | bold-standout use extra bright or bold with standout mode")); |
1211 | ||
1212 | const std::string help_tui_border_mode | |
1213 | = (_("\ | |
1214 | This variable controls the attributes to use for the window borders:\n") | |
1215 | + help_attribute_mode); | |
dcb16346 TV |
1216 | |
1217 | add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums, | |
1218 | &tui_border_mode, _("\ | |
1219 | Set the attribute mode to use for the TUI window borders."), _("\ | |
1220 | Show the attribute mode to use for the TUI window borders."), | |
45601fb8 | 1221 | help_tui_border_mode.c_str (), |
7806cea7 TT |
1222 | tui_set_var_cmd, |
1223 | show_tui_border_mode, | |
1224 | &tui_setlist, &tui_showlist); | |
1225 | ||
45601fb8 TV |
1226 | const std::string help_tui_active_border_mode |
1227 | = (_("\ | |
1228 | This variable controls the attributes to use for the active window borders:\n") | |
1229 | + help_attribute_mode); | |
1230 | ||
7806cea7 TT |
1231 | add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums, |
1232 | &tui_active_border_mode, _("\ | |
1233 | Set the attribute mode to use for the active TUI window border."), _("\ | |
dcb16346 | 1234 | Show the attribute mode to use for the active TUI window border."), |
45601fb8 | 1235 | help_tui_active_border_mode.c_str (), |
7806cea7 TT |
1236 | tui_set_var_cmd, |
1237 | show_tui_active_border_mode, | |
1238 | &tui_setlist, &tui_showlist); | |
1239 | ||
1240 | add_setshow_zuinteger_cmd ("tab-width", no_class, | |
1241 | &internal_tab_width, _("\ | |
1242 | Set the tab width, in characters, for the TUI."), _("\ | |
2829d6da | 1243 | Show the tab width, in characters, for the TUI."), _("\ |
7806cea7 TT |
1244 | This variable controls how many spaces are used to display a tab character."), |
1245 | tui_set_tab_width, tui_show_tab_width, | |
1246 | &tui_setlist, &tui_showlist); | |
45e42163 TT |
1247 | |
1248 | add_setshow_boolean_cmd ("tui-resize-message", class_maintenance, | |
1249 | &resize_message, _("\ | |
1250 | Set TUI resize messaging."), _("\ | |
1251 | Show TUI resize messaging."), _("\ | |
1252 | When enabled GDB will print a message when the terminal is resized."), | |
1253 | nullptr, | |
1254 | show_tui_resize_message, | |
1255 | &maintenance_set_cmdlist, | |
1256 | &maintenance_show_cmdlist); | |
d1da6b01 TT |
1257 | |
1258 | add_setshow_boolean_cmd ("compact-source", class_tui, | |
1259 | &compact_source, _("\ | |
1260 | Set whether the TUI source window is compact."), _("\ | |
1261 | Show whether the TUI source window is compact."), _("\ | |
1262 | This variable controls whether the TUI source window is shown\n\ | |
2093c2af | 1263 | in a compact form. The compact form uses less horizontal space."), |
d1da6b01 TT |
1264 | tui_set_compact_source, tui_show_compact_source, |
1265 | &tui_setlist, &tui_showlist); | |
a2a7af0c | 1266 | |
0f6a6994 MG |
1267 | add_setshow_boolean_cmd ("mouse-events", class_tui, |
1268 | &tui_enable_mouse, _("\ | |
1269 | Set whether TUI mode handles mouse clicks."), _("\ | |
1270 | Show whether TUI mode handles mouse clicks."), _("\ | |
1271 | When on (default), mouse clicks control the TUI and can be accessed by Python\n\ | |
1272 | extensions. When off, mouse clicks are handled by the terminal, enabling\n\ | |
1273 | terminal-native text selection."), | |
1274 | nullptr, | |
1275 | show_tui_mouse_events, | |
1276 | &tui_setlist, &tui_showlist); | |
1277 | ||
92c1d07d PA |
1278 | add_setshow_boolean_cmd ("tui-current-position", class_maintenance, |
1279 | &style_tui_current_position, _("\ | |
1280 | Set whether to style text highlighted by the TUI's current position indicator."), | |
1281 | _("\ | |
1282 | Show whether to style text highlighted by the TUI's current position indicator."), | |
1283 | _("\ | |
1284 | When enabled, the source and assembly code highlighted by the TUI's current\n\ | |
1285 | position indicator is styled."), | |
1286 | set_style_tui_current_position, | |
1287 | show_style_tui_current_position, | |
1288 | &style_set_list, | |
1289 | &style_show_list); | |
1290 | ||
58b77c6a TV |
1291 | add_setshow_boolean_cmd ("tui-left-margin-verbose", class_maintenance, |
1292 | &tui_left_margin_verbose, _("\ | |
1293 | Set whether the left margin should use '_' and '0' instead of spaces."), | |
1294 | _("\ | |
1295 | Show whether the left margin should use '_' and '0' instead of spaces."), | |
1296 | _("\ | |
1297 | When enabled, the left margin will use '_' and '0' instead of spaces."), | |
1298 | nullptr, | |
1299 | nullptr, | |
1300 | &maintenance_set_cmdlist, | |
1301 | &maintenance_show_cmdlist); | |
1302 | ||
c90e7d63 SM |
1303 | tui_border_style.changed.attach (tui_rehighlight_all, "tui-win"); |
1304 | tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win"); | |
7806cea7 | 1305 | } |