1 /* TUI window generic functions.
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
5 Contributed by Hewlett-Packard Company.
7 This file is part of GDB.
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.
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.
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/>. */
22 /* This module contains procedures for handling tui window functions
23 like resize, scrolling, scrolling, changing focus, etc.
25 Author: Susan B. Macchia */
30 #include "breakpoint.h"
32 #include "cli/cli-cmds.h"
35 #include "event-loop.h"
38 #include "tui/tui-io.h"
39 #include "tui/tui-command.h"
40 #include "tui/tui-data.h"
41 #include "tui/tui-layout.h"
42 #include "tui/tui-wingeneral.h"
43 #include "tui/tui-stack.h"
44 #include "tui/tui-regs.h"
45 #include "tui/tui-disasm.h"
46 #include "tui/tui-source.h"
47 #include "tui/tui-winsource.h"
48 #include "tui/tui-win.h"
50 #include "gdb_curses.h"
52 #include "readline/readline.h"
56 /*******************************
58 ********************************/
59 static enum tui_status
tui_adjust_win_heights (struct tui_win_info
*,
61 static int new_height_ok (struct tui_win_info
*, int);
62 static void tui_set_tab_width_command (const char *, int);
63 static void tui_refresh_all_command (const char *, int);
64 static void tui_all_windows_info (const char *, int);
65 static void tui_scroll_forward_command (const char *, int);
66 static void tui_scroll_backward_command (const char *, int);
67 static void tui_scroll_left_command (const char *, int);
68 static void tui_scroll_right_command (const char *, int);
69 static void parse_scrolling_args (const char *,
70 struct tui_win_info
**,
74 /***************************************
76 ***************************************/
77 #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
78 #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
80 /***************************************
82 ***************************************/
85 # define ACS_LRCORNER '+'
88 # define ACS_LLCORNER '+'
91 # define ACS_ULCORNER '+'
94 # define ACS_URCORNER '+'
97 # define ACS_HLINE '-'
100 # define ACS_VLINE '|'
103 /* Possible values for tui-border-kind variable. */
104 static const char *const tui_border_kind_enums
[] = {
111 /* Possible values for tui-border-mode and tui-active-border-mode. */
112 static const char *const tui_border_mode_enums
[] = {
129 /* Translation table for border-mode variables.
130 The list of values must be terminated by a NULL.
131 After the NULL value, an entry defines the default. */
132 struct tui_translate tui_border_mode_translate
[] = {
133 { "normal", A_NORMAL
},
134 { "standout", A_STANDOUT
},
135 { "reverse", A_REVERSE
},
137 { "half-standout", A_DIM
| A_STANDOUT
},
139 { "bold-standout", A_BOLD
| A_STANDOUT
},
141 { "normal", A_NORMAL
}
144 /* Translation tables for border-kind, one for each border
145 character (see wborder, border curses operations).
146 -1 is used to indicate the ACS because ACS characters
147 are determined at run time by curses (depends on terminal). */
148 struct tui_translate tui_border_kind_translate_vline
[] = {
156 struct tui_translate tui_border_kind_translate_hline
[] = {
164 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
172 struct tui_translate tui_border_kind_translate_urcorner
[] = {
180 struct tui_translate tui_border_kind_translate_llcorner
[] = {
188 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
197 /* Tui configuration variables controlled with set/show command. */
198 const char *tui_active_border_mode
= "bold-standout";
200 show_tui_active_border_mode (struct ui_file
*file
,
202 struct cmd_list_element
*c
,
205 fprintf_filtered (file
, _("\
206 The attribute mode to use for the active TUI window border is \"%s\".\n"),
210 const char *tui_border_mode
= "normal";
212 show_tui_border_mode (struct ui_file
*file
,
214 struct cmd_list_element
*c
,
217 fprintf_filtered (file
, _("\
218 The attribute mode to use for the TUI window borders is \"%s\".\n"),
222 const char *tui_border_kind
= "acs";
224 show_tui_border_kind (struct ui_file
*file
,
226 struct cmd_list_element
*c
,
229 fprintf_filtered (file
, _("The kind of border for TUI windows is \"%s\".\n"),
234 /* Tui internal configuration variables. These variables are updated
235 by tui_update_variables to reflect the tui configuration
237 chtype tui_border_vline
;
238 chtype tui_border_hline
;
239 chtype tui_border_ulcorner
;
240 chtype tui_border_urcorner
;
241 chtype tui_border_llcorner
;
242 chtype tui_border_lrcorner
;
244 int tui_border_attrs
;
245 int tui_active_border_attrs
;
247 /* Identify the item in the translation table.
248 When the item is not recognized, use the default entry. */
249 static struct tui_translate
*
250 translate (const char *name
, struct tui_translate
*table
)
254 if (name
&& strcmp (table
->name
, name
) == 0)
259 /* Not found, return default entry. */
264 /* Update the tui internal configuration according to gdb settings.
265 Returns 1 if the configuration has changed and the screen should
268 tui_update_variables (void)
271 struct tui_translate
*entry
;
273 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
274 if (tui_border_attrs
!= entry
->value
)
276 tui_border_attrs
= entry
->value
;
279 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
280 if (tui_active_border_attrs
!= entry
->value
)
282 tui_active_border_attrs
= entry
->value
;
286 /* If one corner changes, all characters are changed.
287 Only check the first one. The ACS characters are determined at
288 run time by curses terminal management. */
289 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
290 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
292 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
295 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
296 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
298 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
299 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
301 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
302 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
304 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
305 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
307 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
308 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
314 set_tui_cmd (const char *args
, int from_tty
)
319 show_tui_cmd (const char *args
, int from_tty
)
323 static struct cmd_list_element
*tuilist
;
326 tui_command (const char *args
, int from_tty
)
328 printf_unfiltered (_("\"tui\" must be followed by the name of a "
330 help_list (tuilist
, "tui ", all_commands
, gdb_stdout
);
333 struct cmd_list_element
**
334 tui_get_cmd_list (void)
337 add_prefix_cmd ("tui", class_tui
, tui_command
,
338 _("Text User Interface commands."),
339 &tuilist
, "tui ", 0, &cmdlist
);
343 /* The set_func hook of "set tui ..." commands that affect the window
344 borders on the TUI display. */
346 tui_set_var_cmd (const char *null_args
,
347 int from_tty
, struct cmd_list_element
*c
)
349 if (tui_update_variables () && tui_active
)
350 tui_rehighlight_all ();
353 /* Generic window name completion function. Complete window name pointed
354 to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
355 window names 'next' and 'prev' will also be considered as possible
356 completions of the window name. */
359 window_name_completer (completion_tracker
&tracker
,
360 int include_next_prev_p
,
361 const char *text
, const char *word
)
363 std::vector
<const char *> completion_name_vec
;
365 for (tui_win_info
*win_info
: all_tui_windows ())
367 const char *completion_name
= NULL
;
369 /* We can't focus on an invisible window. */
370 if (!win_info
->is_visible ())
373 completion_name
= win_info
->name ();
374 gdb_assert (completion_name
!= NULL
);
375 completion_name_vec
.push_back (completion_name
);
378 /* If no windows are considered visible then the TUI has not yet been
379 initialized. But still "focus src" and "focus cmd" will work because
380 invoking the focus command will entail initializing the TUI which sets the
381 default layout to SRC_COMMAND. */
382 if (completion_name_vec
.empty ())
384 completion_name_vec
.push_back (SRC_NAME
);
385 completion_name_vec
.push_back (CMD_NAME
);
388 if (include_next_prev_p
)
390 completion_name_vec
.push_back ("next");
391 completion_name_vec
.push_back ("prev");
395 completion_name_vec
.push_back (NULL
);
396 complete_on_enum (tracker
, completion_name_vec
.data (), text
, word
);
399 /* Complete possible window names to focus on. TEXT is the complete text
400 entered so far, WORD is the word currently being completed. */
403 focus_completer (struct cmd_list_element
*ignore
,
404 completion_tracker
&tracker
,
405 const char *text
, const char *word
)
407 window_name_completer (tracker
, 1, text
, word
);
410 /* Complete possible window names for winheight command. TEXT is the
411 complete text entered so far, WORD is the word currently being
415 winheight_completer (struct cmd_list_element
*ignore
,
416 completion_tracker
&tracker
,
417 const char *text
, const char *word
)
419 /* The first word is the window name. That we can complete. Subsequent
420 words can't be completed. */
424 window_name_completer (tracker
, 0, text
, word
);
427 /* Update gdb's knowledge of the terminal size. */
429 tui_update_gdb_sizes (void)
435 width
= TUI_CMD_WIN
->width
;
436 height
= TUI_CMD_WIN
->height
;
440 width
= tui_term_width ();
441 height
= tui_term_height ();
444 set_screen_width_and_height (width
, height
);
448 /* Set the logical focus to win_info. */
450 tui_set_win_focus_to (struct tui_win_info
*win_info
)
452 if (win_info
!= NULL
)
454 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
456 tui_unhighlight_win (win_with_focus
);
457 tui_set_win_with_focus (win_info
);
458 tui_highlight_win (win_info
);
464 tui_win_info::forward_scroll (int num_to_scroll
)
466 if (num_to_scroll
== 0)
467 num_to_scroll
= height
- 3;
469 do_scroll_vertical (num_to_scroll
);
473 tui_win_info::backward_scroll (int num_to_scroll
)
475 if (num_to_scroll
== 0)
476 num_to_scroll
= height
- 3;
478 do_scroll_vertical (-num_to_scroll
);
483 tui_win_info::left_scroll (int num_to_scroll
)
485 if (num_to_scroll
== 0)
488 do_scroll_horizontal (num_to_scroll
);
493 tui_win_info::right_scroll (int num_to_scroll
)
495 if (num_to_scroll
== 0)
498 do_scroll_horizontal (-num_to_scroll
);
503 tui_refresh_all_win (void)
505 clearok (curscr
, TRUE
);
510 tui_rehighlight_all (void)
512 for (tui_win_info
*win_info
: all_tui_windows ())
513 win_info
->check_and_display_highlight_if_needed ();
516 /* Resize all the windows based on the terminal size. This function
517 gets called from within the readline SIGWINCH handler. */
519 tui_resize_all (void)
521 int height_diff
, width_diff
;
522 int screenheight
, screenwidth
;
524 rl_get_screen_size (&screenheight
, &screenwidth
);
525 width_diff
= screenwidth
- tui_term_width ();
526 height_diff
= screenheight
- tui_term_height ();
527 if (height_diff
|| width_diff
)
529 enum tui_layout_type cur_layout
= tui_current_layout ();
530 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
531 struct tui_win_info
*first_win
;
532 struct tui_win_info
*second_win
;
533 tui_source_window_base
*src_win
;
534 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
535 int new_height
, split_diff
, cmd_split_diff
, num_wins_displayed
= 2;
537 #ifdef HAVE_RESIZE_TERM
538 resize_term (screenheight
, screenwidth
);
540 /* Turn keypad off while we resize. */
541 if (win_with_focus
!= TUI_CMD_WIN
)
542 keypad (TUI_CMD_WIN
->handle
, FALSE
);
543 tui_update_gdb_sizes ();
544 tui_set_term_height_to (screenheight
);
545 tui_set_term_width_to (screenwidth
);
546 if (cur_layout
== SRC_DISASSEM_COMMAND
547 || cur_layout
== SRC_DATA_COMMAND
548 || cur_layout
== DISASSEM_DATA_COMMAND
)
549 num_wins_displayed
++;
550 split_diff
= height_diff
/ num_wins_displayed
;
551 cmd_split_diff
= split_diff
;
552 if (height_diff
% num_wins_displayed
)
559 /* Now adjust each window. */
560 /* erase + clearok are used instead of a straightforward clear as
561 AIX 5.3 does not define clear. */
563 clearok (curscr
, TRUE
);
568 case DISASSEM_COMMAND
:
569 src_win
= *(tui_source_windows ().begin ());
570 /* Check for invalid heights. */
571 if (height_diff
== 0)
572 new_height
= src_win
->height
;
573 else if ((src_win
->height
+ split_diff
) >=
574 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
575 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
576 else if ((src_win
->height
+ split_diff
) <= 0)
577 new_height
= MIN_WIN_HEIGHT
;
579 new_height
= src_win
->height
+ split_diff
;
581 src_win
->resize (new_height
, screenwidth
, 0, 0);
583 locator
->resize (2 /* 1 */, screenwidth
,
586 new_height
= screenheight
- (new_height
+ 1);
587 TUI_CMD_WIN
->resize (new_height
, screenwidth
,
588 0, locator
->origin
.y
+ 1);
591 if (cur_layout
== SRC_DISASSEM_COMMAND
)
593 src_win
= TUI_SRC_WIN
;
595 second_win
= TUI_DISASM_WIN
;
599 first_win
= TUI_DATA_WIN
;
600 src_win
= *(tui_source_windows ().begin ());
601 second_win
= src_win
;
603 /* Change the first window's height/width. */
604 /* Check for invalid heights. */
605 if (height_diff
== 0)
606 new_height
= first_win
->height
;
607 else if ((first_win
->height
+
608 second_win
->height
+ (split_diff
* 2)) >=
609 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
610 new_height
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
611 else if ((first_win
->height
+ split_diff
) <= 0)
612 new_height
= MIN_WIN_HEIGHT
;
614 new_height
= first_win
->height
+ split_diff
;
616 first_win
->resize (new_height
, screenwidth
, 0, 0);
618 /* Change the second window's height/width. */
619 /* Check for invalid heights. */
620 if (height_diff
== 0)
621 new_height
= second_win
->height
;
622 else if ((first_win
->height
+
623 second_win
->height
+ (split_diff
* 2)) >=
624 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
626 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
628 new_height
= (new_height
/ 2) + 1;
632 else if ((second_win
->height
+ split_diff
) <= 0)
633 new_height
= MIN_WIN_HEIGHT
;
635 new_height
= second_win
->height
+ split_diff
;
637 second_win
->resize (new_height
, screenwidth
,
638 0, first_win
->height
- 1);
640 locator
->resize (2 /* 1 */, screenwidth
,
641 0, second_win
->origin
.y
+ new_height
);
643 /* Change the command window's height/width. */
644 new_height
= screenheight
- (locator
->origin
.y
+ 1);
645 TUI_CMD_WIN
->resize (new_height
, screenwidth
,
646 0, locator
->origin
.y
+ 1);
650 tui_delete_invisible_windows ();
651 /* Turn keypad back on, unless focus is in the command
653 if (win_with_focus
!= TUI_CMD_WIN
)
654 keypad (TUI_CMD_WIN
->handle
, TRUE
);
659 /* Token for use by TUI's asynchronous SIGWINCH handler. */
660 static struct async_signal_handler
*tui_sigwinch_token
;
662 /* TUI's SIGWINCH signal handler. */
664 tui_sigwinch_handler (int signal
)
666 mark_async_signal_handler (tui_sigwinch_token
);
667 tui_set_win_resized_to (TRUE
);
670 /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
672 tui_async_resize_screen (gdb_client_data arg
)
674 rl_resize_terminal ();
678 int screen_height
, screen_width
;
680 rl_get_screen_size (&screen_height
, &screen_width
);
681 set_screen_width_and_height (screen_width
, screen_height
);
683 /* win_resized is left set so that the next call to tui_enable()
684 resizes the TUI windows. */
688 tui_set_win_resized_to (FALSE
);
690 tui_refresh_all_win ();
691 tui_update_gdb_sizes ();
692 tui_redisplay_readline ();
697 /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
698 uninstalled when we exit TUI, so the handler should not assume that TUI is
701 tui_initialize_win (void)
705 = create_async_signal_handler (tui_async_resize_screen
, NULL
);
708 #ifdef HAVE_SIGACTION
709 struct sigaction old_winch
;
711 memset (&old_winch
, 0, sizeof (old_winch
));
712 old_winch
.sa_handler
= &tui_sigwinch_handler
;
714 old_winch
.sa_flags
= SA_RESTART
;
716 sigaction (SIGWINCH
, &old_winch
, NULL
);
718 signal (SIGWINCH
, &tui_sigwinch_handler
);
725 /*************************
726 ** STATIC LOCAL FUNCTIONS
727 **************************/
731 tui_scroll_forward_command (const char *arg
, int from_tty
)
733 int num_to_scroll
= 1;
734 struct tui_win_info
*win_to_scroll
;
736 /* Make sure the curses mode is enabled. */
739 parse_scrolling_args (arg
, &win_to_scroll
, NULL
);
741 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
742 win_to_scroll
->forward_scroll (num_to_scroll
);
747 tui_scroll_backward_command (const char *arg
, int from_tty
)
749 int num_to_scroll
= 1;
750 struct tui_win_info
*win_to_scroll
;
752 /* Make sure the curses mode is enabled. */
755 parse_scrolling_args (arg
, &win_to_scroll
, NULL
);
757 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
758 win_to_scroll
->backward_scroll (num_to_scroll
);
763 tui_scroll_left_command (const char *arg
, int from_tty
)
766 struct tui_win_info
*win_to_scroll
;
768 /* Make sure the curses mode is enabled. */
770 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
771 win_to_scroll
->left_scroll (num_to_scroll
);
776 tui_scroll_right_command (const char *arg
, int from_tty
)
779 struct tui_win_info
*win_to_scroll
;
781 /* Make sure the curses mode is enabled. */
783 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
784 win_to_scroll
->right_scroll (num_to_scroll
);
788 /* Set focus to the window named by 'arg'. */
790 tui_set_focus_command (const char *arg
, int from_tty
)
796 char *buf_ptr
= xstrdup (arg
);
798 struct tui_win_info
*win_info
= NULL
;
800 for (i
= 0; (i
< strlen (buf_ptr
)); i
++)
801 buf_ptr
[i
] = tolower (arg
[i
]);
803 if (subset_compare (buf_ptr
, "next"))
804 win_info
= tui_next_win (tui_win_with_focus ());
805 else if (subset_compare (buf_ptr
, "prev"))
806 win_info
= tui_prev_win (tui_win_with_focus ());
808 win_info
= tui_partial_win_by_name (buf_ptr
);
810 if (win_info
== NULL
|| !win_info
->is_visible ())
811 warning (_("Invalid window specified. \n\
812 The window name specified must be valid and visible.\n"));
815 tui_set_win_focus_to (win_info
);
816 keypad (TUI_CMD_WIN
->handle
, (win_info
!= TUI_CMD_WIN
));
820 printf_filtered (_("Focus set to %s window.\n"),
821 tui_win_with_focus ()->name ());
824 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE
);
828 tui_all_windows_info (const char *arg
, int from_tty
)
830 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
831 struct ui_out
*uiout
= current_uiout
;
833 ui_out_emit_table
table_emitter (uiout
, 3, -1, "tui-windows");
834 uiout
->table_header (10, ui_left
, "name", "Name");
835 uiout
->table_header (5, ui_right
, "lines", "Lines");
836 uiout
->table_header (10, ui_left
, "focus", "Focus");
837 uiout
->table_body ();
839 for (tui_win_info
*win_info
: all_tui_windows ())
840 if (win_info
->is_visible ())
842 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
844 uiout
->field_string ("name", win_info
->name ());
845 uiout
->field_signed ("lines", win_info
->height
);
846 if (win_with_focus
== win_info
)
847 uiout
->field_string ("focus", _("(has focus)"));
849 uiout
->field_skip ("focus");
856 tui_refresh_all_command (const char *arg
, int from_tty
)
858 /* Make sure the curses mode is enabled. */
861 tui_refresh_all_win ();
864 /* The tab width that should be used by the TUI. */
866 unsigned int tui_tab_width
= DEFAULT_TAB_LEN
;
868 /* The tab width as set by the user. */
870 static unsigned int internal_tab_width
= DEFAULT_TAB_LEN
;
872 /* After the tab width is set, call this to update the relevant
878 for (tui_win_info
*win_info
: all_tui_windows ())
880 if (win_info
->is_visible ())
881 win_info
->update_tab_width ();
885 /* Callback for "set tui tab-width". */
888 tui_set_tab_width (const char *ignore
,
889 int from_tty
, struct cmd_list_element
*c
)
891 if (internal_tab_width
== 0)
893 internal_tab_width
= tui_tab_width
;
894 error (_("Tab width must not be 0"));
897 tui_tab_width
= internal_tab_width
;
901 /* Callback for "show tui tab-width". */
904 tui_show_tab_width (struct ui_file
*file
, int from_tty
,
905 struct cmd_list_element
*c
, const char *value
)
907 fprintf_filtered (gdb_stdout
, _("TUI tab width is %s spaces.\n"), value
);
911 /* Set the tab width of the specified window. */
913 tui_set_tab_width_command (const char *arg
, int from_tty
)
915 /* Make sure the curses mode is enabled. */
923 warning (_("Tab widths greater than 0 must be specified."));
926 internal_tab_width
= ts
;
935 /* Set the height of the specified window. */
937 tui_set_win_height_command (const char *arg
, int from_tty
)
939 /* Make sure the curses mode is enabled. */
943 std::string copy
= arg
;
944 char *buf
= ©
[0];
948 struct tui_win_info
*win_info
;
951 buf_ptr
= strchr (buf_ptr
, ' ');
956 /* Validate the window name. */
957 for (i
= 0; i
< strlen (wname
); i
++)
958 wname
[i
] = tolower (wname
[i
]);
959 win_info
= tui_partial_win_by_name (wname
);
961 if (win_info
== NULL
|| !win_info
->is_visible ())
962 warning (_("Invalid window specified. \n\
963 The window name specified must be valid and visible.\n"));
966 /* Process the size. */
967 while (*(++buf_ptr
) == ' ')
970 if (*buf_ptr
!= (char) 0)
973 int fixed_size
= TRUE
;
976 if (*buf_ptr
== '+' || *buf_ptr
== '-')
983 input_no
= atoi (buf_ptr
);
989 new_height
= input_no
;
991 new_height
= win_info
->height
+ input_no
;
993 /* Now change the window's height, and adjust
994 all other windows around it. */
995 if (tui_adjust_win_heights (win_info
,
996 new_height
) == TUI_FAILURE
)
997 warning (_("Invalid window height specified.\n%s"),
1000 tui_update_gdb_sizes ();
1003 warning (_("Invalid window height specified.\n%s"),
1009 printf_filtered (WIN_HEIGHT_USAGE
);
1012 printf_filtered (WIN_HEIGHT_USAGE
);
1015 /* Function to adjust all window heights around the primary. */
1016 static enum tui_status
1017 tui_adjust_win_heights (struct tui_win_info
*primary_win_info
,
1020 enum tui_status status
= TUI_FAILURE
;
1022 if (new_height_ok (primary_win_info
, new_height
))
1024 status
= TUI_SUCCESS
;
1025 if (new_height
!= primary_win_info
->height
)
1028 struct tui_win_info
*win_info
;
1029 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
1030 enum tui_layout_type cur_layout
= tui_current_layout ();
1031 int width
= tui_term_width ();
1033 diff
= (new_height
- primary_win_info
->height
) * (-1);
1034 if (cur_layout
== SRC_COMMAND
1035 || cur_layout
== DISASSEM_COMMAND
)
1037 struct tui_win_info
*src_win_info
;
1039 primary_win_info
->resize (new_height
, width
,
1040 0, primary_win_info
->origin
.y
);
1041 if (primary_win_info
->type
== CMD_WIN
)
1043 win_info
= *(tui_source_windows ().begin ());
1044 src_win_info
= win_info
;
1048 win_info
= tui_win_list
[CMD_WIN
];
1049 src_win_info
= primary_win_info
;
1051 win_info
->resize (win_info
->height
+ diff
, width
,
1052 0, win_info
->origin
.y
);
1053 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1054 if ((src_win_info
->type
== SRC_WIN
1055 || src_win_info
->type
== DISASSEM_WIN
))
1057 tui_source_window_base
*src_base
1058 = (tui_source_window_base
*) src_win_info
;
1059 if (src_base
->content
.empty ())
1060 src_base
->erase_source_content ();
1065 struct tui_win_info
*first_win
;
1066 struct tui_source_window_base
*second_win
;
1067 tui_source_window_base
*src1
;
1069 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1073 second_win
= TUI_DISASM_WIN
;
1078 first_win
= TUI_DATA_WIN
;
1079 second_win
= *(tui_source_windows ().begin ());
1081 if (primary_win_info
== TUI_CMD_WIN
)
1082 { /* Split the change in height accross the 1st & 2nd
1083 windows, adjusting them as well. */
1084 /* Subtract the locator. */
1085 int first_split_diff
= diff
/ 2;
1086 int second_split_diff
= first_split_diff
;
1090 if (first_win
->height
>
1099 second_split_diff
--;
1101 second_split_diff
++;
1104 /* Make sure that the minimum hieghts are
1106 while ((first_win
->height
+ first_split_diff
) < 3)
1109 second_split_diff
--;
1111 while ((second_win
->height
+ second_split_diff
) < 3)
1113 second_split_diff
++;
1116 first_win
->resize (first_win
->height
+ first_split_diff
,
1118 0, first_win
->origin
.y
);
1119 second_win
->resize (second_win
->height
+ second_split_diff
,
1121 0, first_win
->height
- 1);
1122 locator
->resize (2 /* 1 */, width
,
1123 0, (second_win
->origin
.y
1124 + second_win
->height
+ 1));
1126 TUI_CMD_WIN
->resize (new_height
, width
,
1127 0, locator
->origin
.y
+ 1);
1131 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1132 { /* If there is no way to increase the command
1133 window take real estate from the 1st or 2nd
1135 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1139 for (i
= TUI_CMD_WIN
->height
+ diff
;
1141 if (primary_win_info
== first_win
)
1142 second_win
->height
--;
1144 first_win
->height
--;
1147 if (primary_win_info
== first_win
)
1148 first_win
->resize (new_height
, width
, 0, 0);
1150 first_win
->resize (first_win
->height
, width
, 0, 0);
1151 second_win
->origin
.y
= first_win
->height
- 1;
1152 if (primary_win_info
== second_win
)
1153 second_win
->resize (new_height
, width
,
1154 0, first_win
->height
- 1);
1156 second_win
->resize (second_win
->height
, width
,
1157 0, first_win
->height
- 1);
1158 locator
->resize (2 /* 1 */, width
,
1159 0, (second_win
->origin
.y
1160 + second_win
->height
+ 1));
1161 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1162 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1163 TUI_CMD_WIN
->resize (1, width
, 0, locator
->origin
.y
+ 1);
1165 TUI_CMD_WIN
->resize (TUI_CMD_WIN
->height
+ diff
, width
,
1166 0, locator
->origin
.y
+ 1);
1168 if (src1
!= nullptr && src1
->content
.empty ())
1169 src1
->erase_source_content ();
1170 if (second_win
->content
.empty ())
1171 second_win
->erase_source_content ();
1179 /* See tui-data.h. */
1182 tui_win_info::max_height () const
1184 return tui_term_height () - 2;
1188 new_height_ok (struct tui_win_info
*primary_win_info
,
1191 int ok
= (new_height
< tui_term_height ());
1196 enum tui_layout_type cur_layout
= tui_current_layout ();
1198 diff
= (new_height
- primary_win_info
->height
) * (-1);
1199 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1201 ok
= (new_height
<= primary_win_info
->max_height ()
1202 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1204 { /* Check the total height. */
1205 struct tui_win_info
*win_info
;
1207 if (primary_win_info
== TUI_CMD_WIN
)
1208 win_info
= *(tui_source_windows ().begin ());
1210 win_info
= TUI_CMD_WIN
;
1212 (win_info
->height
+ diff
)) <= tui_term_height ());
1217 int cur_total_height
, total_height
, min_height
= 0;
1218 struct tui_win_info
*first_win
;
1219 struct tui_win_info
*second_win
;
1221 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1223 first_win
= TUI_SRC_WIN
;
1224 second_win
= TUI_DISASM_WIN
;
1228 first_win
= TUI_DATA_WIN
;
1229 second_win
= *(tui_source_windows ().begin ());
1231 /* We could simply add all the heights to obtain the same
1232 result but below is more explicit since we subtract 1 for
1233 the line that the first and second windows share, and add
1234 one for the locator. */
1235 total_height
= cur_total_height
=
1236 (first_win
->height
+ second_win
->height
- 1)
1237 + TUI_CMD_WIN
->height
+ 1; /* Locator. */
1238 if (primary_win_info
== TUI_CMD_WIN
)
1240 /* Locator included since first & second win share a line. */
1241 ok
= ((first_win
->height
+
1242 second_win
->height
+ diff
) >=
1243 (MIN_WIN_HEIGHT
* 2)
1244 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1247 total_height
= new_height
+
1248 (first_win
->height
+
1249 second_win
->height
+ diff
);
1250 min_height
= MIN_CMD_WIN_HEIGHT
;
1255 min_height
= MIN_WIN_HEIGHT
;
1257 /* First see if we can increase/decrease the command
1258 window. And make sure that the command window is at
1260 ok
= ((TUI_CMD_WIN
->height
+ diff
) > 0);
1262 { /* Looks like we have to increase/decrease one of
1263 the other windows. */
1264 if (primary_win_info
== first_win
)
1265 ok
= (second_win
->height
+ diff
) >= min_height
;
1267 ok
= (first_win
->height
+ diff
) >= min_height
;
1271 if (primary_win_info
== first_win
)
1272 total_height
= new_height
+
1273 second_win
->height
+
1274 TUI_CMD_WIN
->height
+ diff
;
1276 total_height
= new_height
+
1278 TUI_CMD_WIN
->height
+ diff
;
1281 /* Now make sure that the proposed total height doesn't
1282 exceed the old total height. */
1284 ok
= (new_height
>= min_height
1285 && total_height
<= cur_total_height
);
1294 parse_scrolling_args (const char *arg
,
1295 struct tui_win_info
**win_to_scroll
,
1300 *win_to_scroll
= tui_win_with_focus ();
1302 /* First set up the default window to scroll, in case there is no
1308 /* Process the number of lines to scroll. */
1309 std::string copy
= arg
;
1311 if (isdigit (*buf_ptr
))
1316 buf_ptr
= strchr (buf_ptr
, ' ');
1317 if (buf_ptr
!= NULL
)
1319 *buf_ptr
= (char) 0;
1321 *num_to_scroll
= atoi (num_str
);
1324 else if (num_to_scroll
)
1325 *num_to_scroll
= atoi (num_str
);
1328 /* Process the window name if one is specified. */
1329 if (buf_ptr
!= NULL
)
1333 if (*buf_ptr
== ' ')
1334 while (*(++buf_ptr
) == ' ')
1337 if (*buf_ptr
!= (char) 0)
1339 /* Validate the window name. */
1340 for (char *p
= buf_ptr
; *p
!= '\0'; p
++)
1348 *win_to_scroll
= tui_partial_win_by_name (wname
);
1350 if (*win_to_scroll
== NULL
)
1351 error (_("Unrecognized window `%s'"), wname
);
1352 if (!(*win_to_scroll
)->is_visible ())
1353 error (_("Window is not visible"));
1354 else if (*win_to_scroll
== TUI_CMD_WIN
)
1355 *win_to_scroll
= *(tui_source_windows ().begin ());
1360 /* Function to initialize gdb commands, for tui window
1364 _initialize_tui_win (void)
1366 static struct cmd_list_element
*tui_setlist
;
1367 static struct cmd_list_element
*tui_showlist
;
1368 struct cmd_list_element
*cmd
;
1370 /* Define the classes of commands.
1371 They will appear in the help list in the reverse of this order. */
1372 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
1373 _("TUI configuration variables."),
1374 &tui_setlist
, "set tui ",
1375 0 /* allow-unknown */, &setlist
);
1376 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
1377 _("TUI configuration variables."),
1378 &tui_showlist
, "show tui ",
1379 0 /* allow-unknown */, &showlist
);
1381 add_com ("refresh", class_tui
, tui_refresh_all_command
,
1382 _("Refresh the terminal display."));
1384 cmd
= add_com ("tabset", class_tui
, tui_set_tab_width_command
, _("\
1385 Set the width (in characters) of tab stops.\n\
1387 deprecate_cmd (cmd
, "set tui tab-width");
1389 cmd
= add_com ("winheight", class_tui
, tui_set_win_height_command
, _("\
1390 Set or modify the height of a specified window.\n"
1392 "Window names are:\n\
1393 src : the source window\n\
1394 cmd : the command window\n\
1395 asm : the disassembly window\n\
1396 regs : the register display"));
1397 add_com_alias ("wh", "winheight", class_tui
, 0);
1398 set_cmd_completer (cmd
, winheight_completer
);
1399 add_info ("win", tui_all_windows_info
,
1400 _("List of all displayed windows."));
1401 cmd
= add_com ("focus", class_tui
, tui_set_focus_command
, _("\
1402 Set focus to named window or next/prev window.\n"
1404 "Valid Window names are:\n\
1405 src : the source window\n\
1406 asm : the disassembly window\n\
1407 regs : the register display\n\
1408 cmd : the command window"));
1409 add_com_alias ("fs", "focus", class_tui
, 0);
1410 set_cmd_completer (cmd
, focus_completer
);
1411 add_com ("+", class_tui
, tui_scroll_forward_command
, _("\
1412 Scroll window forward.\n\
1413 Usage: + [WIN] [N]"));
1414 add_com ("-", class_tui
, tui_scroll_backward_command
, _("\
1415 Scroll window backward.\n\
1416 Usage: - [WIN] [N]"));
1417 add_com ("<", class_tui
, tui_scroll_left_command
, _("\
1418 Scroll window text to the left.\n\
1419 Usage: < [WIN] [N]"));
1420 add_com (">", class_tui
, tui_scroll_right_command
, _("\
1421 Scroll window text to the right.\n\
1422 Usage: > [WIN] [N]"));
1424 /* Define the tui control variables. */
1425 add_setshow_enum_cmd ("border-kind", no_class
, tui_border_kind_enums
,
1426 &tui_border_kind
, _("\
1427 Set the kind of border for TUI windows."), _("\
1428 Show the kind of border for TUI windows."), _("\
1429 This variable controls the border of TUI windows:\n\
1430 space use a white space\n\
1431 ascii use ascii characters + - | for the border\n\
1432 acs use the Alternate Character Set"),
1434 show_tui_border_kind
,
1435 &tui_setlist
, &tui_showlist
);
1437 add_setshow_enum_cmd ("border-mode", no_class
, tui_border_mode_enums
,
1438 &tui_border_mode
, _("\
1439 Set the attribute mode to use for the TUI window borders."), _("\
1440 Show the attribute mode to use for the TUI window borders."), _("\
1441 This variable controls the attributes to use for the window borders:\n\
1442 normal normal display\n\
1443 standout use highlight mode of terminal\n\
1444 reverse use reverse video mode\n\
1445 half use half bright\n\
1446 half-standout use half bright and standout mode\n\
1447 bold use extra bright or bold\n\
1448 bold-standout use extra bright or bold with standout mode"),
1450 show_tui_border_mode
,
1451 &tui_setlist
, &tui_showlist
);
1453 add_setshow_enum_cmd ("active-border-mode", no_class
, tui_border_mode_enums
,
1454 &tui_active_border_mode
, _("\
1455 Set the attribute mode to use for the active TUI window border."), _("\
1456 Show the attribute mode to use for the active TUI window border."), _("\
1457 This variable controls the attributes to use for the active window border:\n\
1458 normal normal display\n\
1459 standout use highlight mode of terminal\n\
1460 reverse use reverse video mode\n\
1461 half use half bright\n\
1462 half-standout use half bright and standout mode\n\
1463 bold use extra bright or bold\n\
1464 bold-standout use extra bright or bold with standout mode"),
1466 show_tui_active_border_mode
,
1467 &tui_setlist
, &tui_showlist
);
1469 add_setshow_zuinteger_cmd ("tab-width", no_class
,
1470 &internal_tab_width
, _("\
1471 Set the tab width, in characters, for the TUI."), _("\
1472 Show the tab witdh, in characters, for the TUI."), _("\
1473 This variable controls how many spaces are used to display a tab character."),
1474 tui_set_tab_width
, tui_show_tab_width
,
1475 &tui_setlist
, &tui_showlist
);