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