Remove tui_delete_invisible_windows and tui_make_all_invisible
[binutils-gdb.git] / gdb / tui / tui-win.c
1 /* TUI window generic functions.
2
3 Copyright (C) 1998-2020 Free Software Foundation, Inc.
4
5 Contributed by Hewlett-Packard Company.
6
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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 */
26
27 #include "defs.h"
28 #include "command.h"
29 #include "symtab.h"
30 #include "breakpoint.h"
31 #include "frame.h"
32 #include "cli/cli-cmds.h"
33 #include "cli/cli-style.h"
34 #include "top.h"
35 #include "source.h"
36 #include "event-loop.h"
37 #include "gdbcmd.h"
38
39 #include "tui/tui.h"
40 #include "tui/tui-io.h"
41 #include "tui/tui-command.h"
42 #include "tui/tui-data.h"
43 #include "tui/tui-layout.h"
44 #include "tui/tui-wingeneral.h"
45 #include "tui/tui-stack.h"
46 #include "tui/tui-regs.h"
47 #include "tui/tui-disasm.h"
48 #include "tui/tui-source.h"
49 #include "tui/tui-winsource.h"
50 #include "tui/tui-win.h"
51
52 #include "gdb_curses.h"
53 #include <ctype.h>
54 #include "readline/readline.h"
55 #include "gdbsupport/gdb_string_view.h"
56
57 #include <signal.h>
58
59 static void tui_set_tab_width_command (const char *, int);
60 static void tui_refresh_all_command (const char *, int);
61 static void tui_all_windows_info (const char *, int);
62 static void tui_scroll_forward_command (const char *, int);
63 static void tui_scroll_backward_command (const char *, int);
64 static void tui_scroll_left_command (const char *, int);
65 static void tui_scroll_right_command (const char *, int);
66 static void parse_scrolling_args (const char *,
67 struct tui_win_info **,
68 int *);
69
70
71 #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
72 #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
73
74 #ifndef ACS_LRCORNER
75 # define ACS_LRCORNER '+'
76 #endif
77 #ifndef ACS_LLCORNER
78 # define ACS_LLCORNER '+'
79 #endif
80 #ifndef ACS_ULCORNER
81 # define ACS_ULCORNER '+'
82 #endif
83 #ifndef ACS_URCORNER
84 # define ACS_URCORNER '+'
85 #endif
86 #ifndef ACS_HLINE
87 # define ACS_HLINE '-'
88 #endif
89 #ifndef ACS_VLINE
90 # define ACS_VLINE '|'
91 #endif
92
93 /* Possible values for tui-border-kind variable. */
94 static const char *const tui_border_kind_enums[] = {
95 "space",
96 "ascii",
97 "acs",
98 NULL
99 };
100
101 /* Possible values for tui-border-mode and tui-active-border-mode. */
102 static const char *const tui_border_mode_enums[] = {
103 "normal",
104 "standout",
105 "reverse",
106 "half",
107 "half-standout",
108 "bold",
109 "bold-standout",
110 NULL
111 };
112
113 struct tui_translate
114 {
115 const char *name;
116 int value;
117 };
118
119 /* Translation table for border-mode variables.
120 The list of values must be terminated by a NULL.
121 After the NULL value, an entry defines the default. */
122 static struct tui_translate tui_border_mode_translate[] = {
123 { "normal", A_NORMAL },
124 { "standout", A_STANDOUT },
125 { "reverse", A_REVERSE },
126 { "half", A_DIM },
127 { "half-standout", A_DIM | A_STANDOUT },
128 { "bold", A_BOLD },
129 { "bold-standout", A_BOLD | A_STANDOUT },
130 { 0, 0 },
131 { "normal", A_NORMAL }
132 };
133
134 /* Translation tables for border-kind, one for each border
135 character (see wborder, border curses operations).
136 -1 is used to indicate the ACS because ACS characters
137 are determined at run time by curses (depends on terminal). */
138 static struct tui_translate tui_border_kind_translate_vline[] = {
139 { "space", ' ' },
140 { "ascii", '|' },
141 { "acs", -1 },
142 { 0, 0 },
143 { "ascii", '|' }
144 };
145
146 static struct tui_translate tui_border_kind_translate_hline[] = {
147 { "space", ' ' },
148 { "ascii", '-' },
149 { "acs", -1 },
150 { 0, 0 },
151 { "ascii", '-' }
152 };
153
154 static struct tui_translate tui_border_kind_translate_ulcorner[] = {
155 { "space", ' ' },
156 { "ascii", '+' },
157 { "acs", -1 },
158 { 0, 0 },
159 { "ascii", '+' }
160 };
161
162 static struct tui_translate tui_border_kind_translate_urcorner[] = {
163 { "space", ' ' },
164 { "ascii", '+' },
165 { "acs", -1 },
166 { 0, 0 },
167 { "ascii", '+' }
168 };
169
170 static struct tui_translate tui_border_kind_translate_llcorner[] = {
171 { "space", ' ' },
172 { "ascii", '+' },
173 { "acs", -1 },
174 { 0, 0 },
175 { "ascii", '+' }
176 };
177
178 static struct tui_translate tui_border_kind_translate_lrcorner[] = {
179 { "space", ' ' },
180 { "ascii", '+' },
181 { "acs", -1 },
182 { 0, 0 },
183 { "ascii", '+' }
184 };
185
186
187 /* Tui configuration variables controlled with set/show command. */
188 static const char *tui_active_border_mode = "bold-standout";
189 static void
190 show_tui_active_border_mode (struct ui_file *file,
191 int from_tty,
192 struct cmd_list_element *c,
193 const char *value)
194 {
195 fprintf_filtered (file, _("\
196 The attribute mode to use for the active TUI window border is \"%s\".\n"),
197 value);
198 }
199
200 static const char *tui_border_mode = "normal";
201 static void
202 show_tui_border_mode (struct ui_file *file,
203 int from_tty,
204 struct cmd_list_element *c,
205 const char *value)
206 {
207 fprintf_filtered (file, _("\
208 The attribute mode to use for the TUI window borders is \"%s\".\n"),
209 value);
210 }
211
212 static const char *tui_border_kind = "acs";
213 static void
214 show_tui_border_kind (struct ui_file *file,
215 int from_tty,
216 struct cmd_list_element *c,
217 const char *value)
218 {
219 fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
220 value);
221 }
222
223
224 /* Tui internal configuration variables. These variables are updated
225 by tui_update_variables to reflect the tui configuration
226 variables. */
227 chtype tui_border_vline;
228 chtype tui_border_hline;
229 chtype tui_border_ulcorner;
230 chtype tui_border_urcorner;
231 chtype tui_border_llcorner;
232 chtype tui_border_lrcorner;
233
234 int tui_border_attrs;
235 int tui_active_border_attrs;
236
237 /* Identify the item in the translation table.
238 When the item is not recognized, use the default entry. */
239 static struct tui_translate *
240 translate (const char *name, struct tui_translate *table)
241 {
242 while (table->name)
243 {
244 if (name && strcmp (table->name, name) == 0)
245 return table;
246 table++;
247 }
248
249 /* Not found, return default entry. */
250 table++;
251 return table;
252 }
253
254 /* Update the tui internal configuration according to gdb settings.
255 Returns 1 if the configuration has changed and the screen should
256 be redrawn. */
257 bool
258 tui_update_variables ()
259 {
260 bool need_redraw = false;
261 struct tui_translate *entry;
262
263 entry = translate (tui_border_mode, tui_border_mode_translate);
264 if (tui_border_attrs != entry->value)
265 {
266 tui_border_attrs = entry->value;
267 need_redraw = true;
268 }
269 entry = translate (tui_active_border_mode, tui_border_mode_translate);
270 if (tui_active_border_attrs != entry->value)
271 {
272 tui_active_border_attrs = entry->value;
273 need_redraw = true;
274 }
275
276 /* If one corner changes, all characters are changed.
277 Only check the first one. The ACS characters are determined at
278 run time by curses terminal management. */
279 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
280 if (tui_border_lrcorner != (chtype) entry->value)
281 {
282 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
283 need_redraw = true;
284 }
285 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
286 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
287
288 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
289 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
290
291 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
292 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
293
294 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
295 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
296
297 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
298 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
299
300 return need_redraw;
301 }
302
303 static void
304 set_tui_cmd (const char *args, int from_tty)
305 {
306 }
307
308 static void
309 show_tui_cmd (const char *args, int from_tty)
310 {
311 }
312
313 static struct cmd_list_element *tuilist;
314
315 static void
316 tui_command (const char *args, int from_tty)
317 {
318 printf_unfiltered (_("\"tui\" must be followed by the name of a "
319 "tui command.\n"));
320 help_list (tuilist, "tui ", all_commands, gdb_stdout);
321 }
322
323 struct cmd_list_element **
324 tui_get_cmd_list (void)
325 {
326 if (tuilist == 0)
327 add_prefix_cmd ("tui", class_tui, tui_command,
328 _("Text User Interface commands."),
329 &tuilist, "tui ", 0, &cmdlist);
330 return &tuilist;
331 }
332
333 /* The set_func hook of "set tui ..." commands that affect the window
334 borders on the TUI display. */
335
336 static void
337 tui_set_var_cmd (const char *null_args,
338 int from_tty, struct cmd_list_element *c)
339 {
340 if (tui_update_variables () && tui_active)
341 tui_rehighlight_all ();
342 }
343
344 \f
345
346 /* True if TUI resizes should print a message. This is used by the
347 test suite. */
348
349 static bool resize_message;
350
351 static void
352 show_tui_resize_message (struct ui_file *file, int from_tty,
353 struct cmd_list_element *c, const char *value)
354 {
355 fprintf_filtered (file, _("TUI resize messaging is %s.\n"), value);
356 }
357
358 \f
359
360 /* Generic window name completion function. Complete window name pointed
361 to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
362 window names 'next' and 'prev' will also be considered as possible
363 completions of the window name. */
364
365 static void
366 window_name_completer (completion_tracker &tracker,
367 int include_next_prev_p,
368 const char *text, const char *word)
369 {
370 std::vector<const char *> completion_name_vec;
371
372 for (tui_win_info *win_info : all_tui_windows ())
373 {
374 const char *completion_name = NULL;
375
376 /* We can't focus on an invisible window. */
377 if (!win_info->is_visible ())
378 continue;
379
380 completion_name = win_info->name ();
381 gdb_assert (completion_name != NULL);
382 completion_name_vec.push_back (completion_name);
383 }
384
385 /* If no windows are considered visible then the TUI has not yet been
386 initialized. But still "focus src" and "focus cmd" will work because
387 invoking the focus command will entail initializing the TUI which sets the
388 default layout to "src". */
389 if (completion_name_vec.empty ())
390 {
391 completion_name_vec.push_back (SRC_NAME);
392 completion_name_vec.push_back (CMD_NAME);
393 }
394
395 if (include_next_prev_p)
396 {
397 completion_name_vec.push_back ("next");
398 completion_name_vec.push_back ("prev");
399 }
400
401
402 completion_name_vec.push_back (NULL);
403 complete_on_enum (tracker, completion_name_vec.data (), text, word);
404 }
405
406 /* Complete possible window names to focus on. TEXT is the complete text
407 entered so far, WORD is the word currently being completed. */
408
409 static void
410 focus_completer (struct cmd_list_element *ignore,
411 completion_tracker &tracker,
412 const char *text, const char *word)
413 {
414 window_name_completer (tracker, 1, text, word);
415 }
416
417 /* Complete possible window names for winheight command. TEXT is the
418 complete text entered so far, WORD is the word currently being
419 completed. */
420
421 static void
422 winheight_completer (struct cmd_list_element *ignore,
423 completion_tracker &tracker,
424 const char *text, const char *word)
425 {
426 /* The first word is the window name. That we can complete. Subsequent
427 words can't be completed. */
428 if (word != text)
429 return;
430
431 window_name_completer (tracker, 0, text, word);
432 }
433
434 /* Update gdb's knowledge of the terminal size. */
435 void
436 tui_update_gdb_sizes (void)
437 {
438 int width, height;
439
440 if (tui_active)
441 {
442 width = TUI_CMD_WIN->width;
443 height = TUI_CMD_WIN->height;
444 }
445 else
446 {
447 width = tui_term_width ();
448 height = tui_term_height ();
449 }
450
451 set_screen_width_and_height (width, height);
452 }
453
454
455 /* Set the logical focus to win_info. */
456 void
457 tui_set_win_focus_to (struct tui_win_info *win_info)
458 {
459 if (win_info != NULL)
460 {
461 struct tui_win_info *win_with_focus = tui_win_with_focus ();
462
463 tui_unhighlight_win (win_with_focus);
464 tui_set_win_with_focus (win_info);
465 tui_highlight_win (win_info);
466 }
467 }
468
469
470 void
471 tui_win_info::forward_scroll (int num_to_scroll)
472 {
473 if (num_to_scroll == 0)
474 num_to_scroll = height - 3;
475
476 do_scroll_vertical (num_to_scroll);
477 }
478
479 void
480 tui_win_info::backward_scroll (int num_to_scroll)
481 {
482 if (num_to_scroll == 0)
483 num_to_scroll = height - 3;
484
485 do_scroll_vertical (-num_to_scroll);
486 }
487
488
489 void
490 tui_win_info::left_scroll (int num_to_scroll)
491 {
492 if (num_to_scroll == 0)
493 num_to_scroll = 1;
494
495 do_scroll_horizontal (num_to_scroll);
496 }
497
498
499 void
500 tui_win_info::right_scroll (int num_to_scroll)
501 {
502 if (num_to_scroll == 0)
503 num_to_scroll = 1;
504
505 do_scroll_horizontal (-num_to_scroll);
506 }
507
508
509 void
510 tui_refresh_all_win (void)
511 {
512 clearok (curscr, TRUE);
513 tui_refresh_all ();
514 }
515
516 void
517 tui_rehighlight_all (void)
518 {
519 for (tui_win_info *win_info : all_tui_windows ())
520 win_info->check_and_display_highlight_if_needed ();
521 }
522
523 /* Resize all the windows based on the terminal size. This function
524 gets called from within the readline SIGWINCH handler. */
525 void
526 tui_resize_all (void)
527 {
528 int height_diff, width_diff;
529 int screenheight, screenwidth;
530
531 rl_get_screen_size (&screenheight, &screenwidth);
532 width_diff = screenwidth - tui_term_width ();
533 height_diff = screenheight - tui_term_height ();
534 if (height_diff || width_diff)
535 {
536 struct tui_win_info *win_with_focus = tui_win_with_focus ();
537
538 #ifdef HAVE_RESIZE_TERM
539 resize_term (screenheight, screenwidth);
540 #endif
541 /* Turn keypad off while we resize. */
542 if (win_with_focus != TUI_CMD_WIN)
543 keypad (TUI_CMD_WIN->handle.get (), FALSE);
544 tui_update_gdb_sizes ();
545 tui_set_term_height_to (screenheight);
546 tui_set_term_width_to (screenwidth);
547
548 /* erase + clearok are used instead of a straightforward clear as
549 AIX 5.3 does not define clear. */
550 erase ();
551 clearok (curscr, TRUE);
552 tui_apply_current_layout ();
553 /* Turn keypad back on, unless focus is in the command
554 window. */
555 if (win_with_focus != TUI_CMD_WIN)
556 keypad (TUI_CMD_WIN->handle.get (), TRUE);
557 }
558 }
559
560 #ifdef SIGWINCH
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. */
565 static void
566 tui_sigwinch_handler (int signal)
567 {
568 mark_async_signal_handler (tui_sigwinch_token);
569 tui_set_win_resized_to (true);
570 }
571
572 /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
573 static void
574 tui_async_resize_screen (gdb_client_data arg)
575 {
576 rl_resize_terminal ();
577
578 if (!tui_active)
579 {
580 int screen_height, screen_width;
581
582 rl_get_screen_size (&screen_height, &screen_width);
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 {
590 tui_set_win_resized_to (false);
591 tui_resize_all ();
592 tui_refresh_all_win ();
593 tui_update_gdb_sizes ();
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 }
601 tui_redisplay_readline ();
602 }
603 }
604 #endif
605
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. */
609 void
610 tui_initialize_win (void)
611 {
612 #ifdef SIGWINCH
613 tui_sigwinch_token
614 = create_async_signal_handler (tui_async_resize_screen, NULL);
615
616 {
617 #ifdef HAVE_SIGACTION
618 struct sigaction old_winch;
619
620 memset (&old_winch, 0, sizeof (old_winch));
621 old_winch.sa_handler = &tui_sigwinch_handler;
622 #ifdef SA_RESTART
623 old_winch.sa_flags = SA_RESTART;
624 #endif
625 sigaction (SIGWINCH, &old_winch, NULL);
626 #else
627 signal (SIGWINCH, &tui_sigwinch_handler);
628 #endif
629 }
630 #endif
631 }
632
633
634 static void
635 tui_scroll_forward_command (const char *arg, int from_tty)
636 {
637 int num_to_scroll = 1;
638 struct tui_win_info *win_to_scroll;
639
640 /* Make sure the curses mode is enabled. */
641 tui_enable ();
642 if (arg == NULL)
643 parse_scrolling_args (arg, &win_to_scroll, NULL);
644 else
645 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
646 win_to_scroll->forward_scroll (num_to_scroll);
647 }
648
649
650 static void
651 tui_scroll_backward_command (const char *arg, int from_tty)
652 {
653 int num_to_scroll = 1;
654 struct tui_win_info *win_to_scroll;
655
656 /* Make sure the curses mode is enabled. */
657 tui_enable ();
658 if (arg == NULL)
659 parse_scrolling_args (arg, &win_to_scroll, NULL);
660 else
661 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
662 win_to_scroll->backward_scroll (num_to_scroll);
663 }
664
665
666 static void
667 tui_scroll_left_command (const char *arg, int from_tty)
668 {
669 int num_to_scroll;
670 struct tui_win_info *win_to_scroll;
671
672 /* Make sure the curses mode is enabled. */
673 tui_enable ();
674 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
675 win_to_scroll->left_scroll (num_to_scroll);
676 }
677
678
679 static void
680 tui_scroll_right_command (const char *arg, int from_tty)
681 {
682 int num_to_scroll;
683 struct tui_win_info *win_to_scroll;
684
685 /* Make sure the curses mode is enabled. */
686 tui_enable ();
687 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
688 win_to_scroll->right_scroll (num_to_scroll);
689 }
690
691
692 /* Answer the window represented by name. */
693 static struct tui_win_info *
694 tui_partial_win_by_name (gdb::string_view name)
695 {
696 struct tui_win_info *best = nullptr;
697
698 if (name != NULL)
699 {
700 for (tui_win_info *item : all_tui_windows ())
701 {
702 const char *cur_name = item->name ();
703
704 if (name == cur_name)
705 return item;
706 if (startswith (cur_name, name))
707 {
708 if (best != nullptr)
709 error (_("Window name \"%*s\" is ambiguous"),
710 (int) name.size (), name.data ());
711 best = item;
712 }
713 }
714 }
715
716 return best;
717 }
718
719 /* Set focus to the window named by 'arg'. */
720 static void
721 tui_set_focus_command (const char *arg, int from_tty)
722 {
723 tui_enable ();
724
725 if (arg != NULL)
726 {
727 struct tui_win_info *win_info = NULL;
728
729 if (subset_compare (arg, "next"))
730 win_info = tui_next_win (tui_win_with_focus ());
731 else if (subset_compare (arg, "prev"))
732 win_info = tui_prev_win (tui_win_with_focus ());
733 else
734 win_info = tui_partial_win_by_name (arg);
735
736 if (win_info == NULL)
737 error (_("Unrecognized window name \"%s\""), arg);
738 if (!win_info->is_visible ())
739 error (_("Window \"%s\" is not visible"), arg);
740
741 tui_set_win_focus_to (win_info);
742 keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
743 printf_filtered (_("Focus set to %s window.\n"),
744 tui_win_with_focus ()->name ());
745 }
746 else
747 error (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
748 }
749
750 static void
751 tui_all_windows_info (const char *arg, int from_tty)
752 {
753 if (!tui_active)
754 {
755 printf_filtered (_("The TUI is not active.\n"));
756 return;
757 }
758
759 struct tui_win_info *win_with_focus = tui_win_with_focus ();
760 struct ui_out *uiout = current_uiout;
761
762 ui_out_emit_table table_emitter (uiout, 3, -1, "tui-windows");
763 uiout->table_header (10, ui_left, "name", "Name");
764 uiout->table_header (5, ui_right, "lines", "Lines");
765 uiout->table_header (10, ui_left, "focus", "Focus");
766 uiout->table_body ();
767
768 for (tui_win_info *win_info : all_tui_windows ())
769 if (win_info->is_visible ())
770 {
771 ui_out_emit_tuple tuple_emitter (uiout, nullptr);
772
773 uiout->field_string ("name", win_info->name ());
774 uiout->field_signed ("lines", win_info->height);
775 if (win_with_focus == win_info)
776 uiout->field_string ("focus", _("(has focus)"));
777 else
778 uiout->field_skip ("focus");
779 uiout->text ("\n");
780 }
781 }
782
783
784 static void
785 tui_refresh_all_command (const char *arg, int from_tty)
786 {
787 /* Make sure the curses mode is enabled. */
788 tui_enable ();
789
790 tui_refresh_all_win ();
791 }
792
793 /* The tab width that should be used by the TUI. */
794
795 unsigned int tui_tab_width = DEFAULT_TAB_LEN;
796
797 /* The tab width as set by the user. */
798
799 static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
800
801 /* After the tab width is set, call this to update the relevant
802 windows. */
803
804 static void
805 update_tab_width ()
806 {
807 for (tui_win_info *win_info : all_tui_windows ())
808 {
809 if (win_info->is_visible ())
810 win_info->update_tab_width ();
811 }
812 }
813
814 /* Callback for "set tui tab-width". */
815
816 static void
817 tui_set_tab_width (const char *ignore,
818 int from_tty, struct cmd_list_element *c)
819 {
820 if (internal_tab_width == 0)
821 {
822 internal_tab_width = tui_tab_width;
823 error (_("Tab width must not be 0"));
824 }
825
826 tui_tab_width = internal_tab_width;
827 update_tab_width ();
828 }
829
830 /* Callback for "show tui tab-width". */
831
832 static void
833 tui_show_tab_width (struct ui_file *file, int from_tty,
834 struct cmd_list_element *c, const char *value)
835 {
836 fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value);
837
838 }
839
840 /* See tui-win.h. */
841
842 bool compact_source = false;
843
844 /* Callback for "set tui compact-source". */
845
846 static void
847 tui_set_compact_source (const char *ignore, int from_tty,
848 struct cmd_list_element *c)
849 {
850 if (TUI_SRC_WIN != nullptr)
851 TUI_SRC_WIN->refill ();
852 }
853
854 /* Callback for "show tui compact-source". */
855
856 static void
857 tui_show_compact_source (struct ui_file *file, int from_tty,
858 struct cmd_list_element *c, const char *value)
859 {
860 printf_filtered (_("TUI source window compactness is %s.\n"), value);
861 }
862
863 /* Set the tab width of the specified window. */
864 static void
865 tui_set_tab_width_command (const char *arg, int from_tty)
866 {
867 /* Make sure the curses mode is enabled. */
868 tui_enable ();
869 if (arg != NULL)
870 {
871 int ts;
872
873 ts = atoi (arg);
874 if (ts <= 0)
875 warning (_("Tab widths greater than 0 must be specified."));
876 else
877 {
878 internal_tab_width = ts;
879 tui_tab_width = ts;
880
881 update_tab_width ();
882 }
883 }
884 }
885
886
887 /* Set the height of the specified window. */
888 static void
889 tui_set_win_height_command (const char *arg, int from_tty)
890 {
891 /* Make sure the curses mode is enabled. */
892 tui_enable ();
893 if (arg != NULL)
894 {
895 const char *buf = arg;
896 const char *buf_ptr = buf;
897 int new_height;
898 struct tui_win_info *win_info;
899
900 buf_ptr = strchr (buf_ptr, ' ');
901 if (buf_ptr != NULL)
902 {
903 /* Validate the window name. */
904 gdb::string_view wname (buf, buf_ptr - buf);
905 win_info = tui_partial_win_by_name (wname);
906
907 if (win_info == NULL)
908 error (_("Unrecognized window name \"%s\""), arg);
909 if (!win_info->is_visible ())
910 error (_("Window \"%s\" is not visible"), arg);
911
912 /* Process the size. */
913 buf_ptr = skip_spaces (buf_ptr);
914
915 if (*buf_ptr != '\0')
916 {
917 bool negate = false;
918 bool fixed_size = true;
919 int input_no;;
920
921 if (*buf_ptr == '+' || *buf_ptr == '-')
922 {
923 if (*buf_ptr == '-')
924 negate = true;
925 fixed_size = false;
926 buf_ptr++;
927 }
928 input_no = atoi (buf_ptr);
929 if (input_no > 0)
930 {
931 if (negate)
932 input_no *= (-1);
933 if (fixed_size)
934 new_height = input_no;
935 else
936 new_height = win_info->height + input_no;
937
938 /* Now change the window's height, and adjust
939 all other windows around it. */
940 tui_adjust_window_height (win_info, new_height);
941 tui_update_gdb_sizes ();
942 }
943 else
944 warning (_("Invalid window height specified.\n%s"),
945 WIN_HEIGHT_USAGE);
946 }
947 }
948 else
949 printf_filtered (WIN_HEIGHT_USAGE);
950 }
951 else
952 printf_filtered (WIN_HEIGHT_USAGE);
953 }
954
955 /* See tui-data.h. */
956
957 int
958 tui_win_info::max_height () const
959 {
960 return tui_term_height () - 2;
961 }
962
963 /* See tui-data.h. */
964
965 int
966 tui_gen_win_info::max_width () const
967 {
968 return tui_term_width () - 2;
969 }
970
971 static void
972 parse_scrolling_args (const char *arg,
973 struct tui_win_info **win_to_scroll,
974 int *num_to_scroll)
975 {
976 if (num_to_scroll)
977 *num_to_scroll = 0;
978 *win_to_scroll = tui_win_with_focus ();
979
980 /* First set up the default window to scroll, in case there is no
981 window name arg. */
982 if (arg != NULL)
983 {
984 char *buf_ptr;
985
986 /* Process the number of lines to scroll. */
987 std::string copy = arg;
988 buf_ptr = &copy[0];
989 if (isdigit (*buf_ptr))
990 {
991 char *num_str;
992
993 num_str = buf_ptr;
994 buf_ptr = strchr (buf_ptr, ' ');
995 if (buf_ptr != NULL)
996 {
997 *buf_ptr = '\0';
998 if (num_to_scroll)
999 *num_to_scroll = atoi (num_str);
1000 buf_ptr++;
1001 }
1002 else if (num_to_scroll)
1003 *num_to_scroll = atoi (num_str);
1004 }
1005
1006 /* Process the window name if one is specified. */
1007 if (buf_ptr != NULL)
1008 {
1009 const char *wname;
1010
1011 wname = skip_spaces (buf_ptr);
1012
1013 if (*wname != '\0')
1014 {
1015 *win_to_scroll = tui_partial_win_by_name (wname);
1016
1017 if (*win_to_scroll == NULL)
1018 error (_("Unrecognized window `%s'"), wname);
1019 if (!(*win_to_scroll)->is_visible ())
1020 error (_("Window is not visible"));
1021 else if (*win_to_scroll == TUI_CMD_WIN)
1022 *win_to_scroll = *(tui_source_windows ().begin ());
1023 }
1024 }
1025 }
1026 }
1027
1028 /* Function to initialize gdb commands, for tui window
1029 manipulation. */
1030
1031 void _initialize_tui_win ();
1032 void
1033 _initialize_tui_win ()
1034 {
1035 static struct cmd_list_element *tui_setlist;
1036 static struct cmd_list_element *tui_showlist;
1037 struct cmd_list_element *cmd;
1038
1039 /* Define the classes of commands.
1040 They will appear in the help list in the reverse of this order. */
1041 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
1042 _("TUI configuration variables."),
1043 &tui_setlist, "set tui ",
1044 0 /* allow-unknown */, &setlist);
1045 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
1046 _("TUI configuration variables."),
1047 &tui_showlist, "show tui ",
1048 0 /* allow-unknown */, &showlist);
1049
1050 add_com ("refresh", class_tui, tui_refresh_all_command,
1051 _("Refresh the terminal display."));
1052
1053 cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1054 Set the width (in characters) of tab stops.\n\
1055 Usage: tabset N"));
1056 deprecate_cmd (cmd, "set tui tab-width");
1057
1058 cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
1059 Set or modify the height of a specified window.\n"
1060 WIN_HEIGHT_USAGE
1061 "Window names are:\n\
1062 src : the source window\n\
1063 cmd : the command window\n\
1064 asm : the disassembly window\n\
1065 regs : the register display"));
1066 add_com_alias ("wh", "winheight", class_tui, 0);
1067 set_cmd_completer (cmd, winheight_completer);
1068 add_info ("win", tui_all_windows_info,
1069 _("List of all displayed windows."));
1070 cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
1071 Set focus to named window or next/prev window.\n"
1072 FOCUS_USAGE
1073 "Valid Window names are:\n\
1074 src : the source window\n\
1075 asm : the disassembly window\n\
1076 regs : the register display\n\
1077 cmd : the command window"));
1078 add_com_alias ("fs", "focus", class_tui, 0);
1079 set_cmd_completer (cmd, focus_completer);
1080 add_com ("+", class_tui, tui_scroll_forward_command, _("\
1081 Scroll window forward.\n\
1082 Usage: + [N] [WIN]\n\
1083 Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\
1084 defaults to 1, and WIN defaults to the currently focused window."));
1085 add_com ("-", class_tui, tui_scroll_backward_command, _("\
1086 Scroll window backward.\n\
1087 Usage: - [N] [WIN]\n\
1088 Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\
1089 defaults to 1, and WIN defaults to the currently focused window."));
1090 add_com ("<", class_tui, tui_scroll_left_command, _("\
1091 Scroll window text to the left.\n\
1092 Usage: < [N] [WIN]\n\
1093 Scroll window WIN N characters left. Both WIN and N are optional, N\n\
1094 defaults to 1, and WIN defaults to the currently focused window."));
1095 add_com (">", class_tui, tui_scroll_right_command, _("\
1096 Scroll window text to the right.\n\
1097 Usage: > [N] [WIN]\n\
1098 Scroll window WIN N characters right. Both WIN and N are optional, N\n\
1099 defaults to 1, and WIN defaults to the currently focused window."));
1100
1101 /* Define the tui control variables. */
1102 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1103 &tui_border_kind, _("\
1104 Set the kind of border for TUI windows."), _("\
1105 Show the kind of border for TUI windows."), _("\
1106 This variable controls the border of TUI windows:\n\
1107 space use a white space\n\
1108 ascii use ascii characters + - | for the border\n\
1109 acs use the Alternate Character Set"),
1110 tui_set_var_cmd,
1111 show_tui_border_kind,
1112 &tui_setlist, &tui_showlist);
1113
1114 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1115 &tui_border_mode, _("\
1116 Set the attribute mode to use for the TUI window borders."), _("\
1117 Show the attribute mode to use for the TUI window borders."), _("\
1118 This variable controls the attributes to use for the window borders:\n\
1119 normal normal display\n\
1120 standout use highlight mode of terminal\n\
1121 reverse use reverse video mode\n\
1122 half use half bright\n\
1123 half-standout use half bright and standout mode\n\
1124 bold use extra bright or bold\n\
1125 bold-standout use extra bright or bold with standout mode"),
1126 tui_set_var_cmd,
1127 show_tui_border_mode,
1128 &tui_setlist, &tui_showlist);
1129
1130 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1131 &tui_active_border_mode, _("\
1132 Set the attribute mode to use for the active TUI window border."), _("\
1133 Show the attribute mode to use for the active TUI window border."), _("\
1134 This variable controls the attributes to use for the active window border:\n\
1135 normal normal display\n\
1136 standout use highlight mode of terminal\n\
1137 reverse use reverse video mode\n\
1138 half use half bright\n\
1139 half-standout use half bright and standout mode\n\
1140 bold use extra bright or bold\n\
1141 bold-standout use extra bright or bold with standout mode"),
1142 tui_set_var_cmd,
1143 show_tui_active_border_mode,
1144 &tui_setlist, &tui_showlist);
1145
1146 add_setshow_zuinteger_cmd ("tab-width", no_class,
1147 &internal_tab_width, _("\
1148 Set the tab width, in characters, for the TUI."), _("\
1149 Show the tab witdh, in characters, for the TUI."), _("\
1150 This variable controls how many spaces are used to display a tab character."),
1151 tui_set_tab_width, tui_show_tab_width,
1152 &tui_setlist, &tui_showlist);
1153
1154 add_setshow_boolean_cmd ("tui-resize-message", class_maintenance,
1155 &resize_message, _("\
1156 Set TUI resize messaging."), _("\
1157 Show TUI resize messaging."), _("\
1158 When enabled GDB will print a message when the terminal is resized."),
1159 nullptr,
1160 show_tui_resize_message,
1161 &maintenance_set_cmdlist,
1162 &maintenance_show_cmdlist);
1163
1164 add_setshow_boolean_cmd ("compact-source", class_tui,
1165 &compact_source, _("\
1166 Set whether the TUI source window is compact."), _("\
1167 Show whether the TUI source window is compact."), _("\
1168 This variable controls whether the TUI source window is shown\n\
1169 in a compact form. The compact form puts the source closer to\n\
1170 the line numbers and uses less horizontal space."),
1171 tui_set_compact_source, tui_show_compact_source,
1172 &tui_setlist, &tui_showlist);
1173
1174 tui_border_style.changed.attach (tui_rehighlight_all);
1175 tui_active_border_style.changed.attach (tui_rehighlight_all);
1176 }