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