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