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