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 static enum tui_status
tui_adjust_win_heights (struct tui_win_info
*,
58 static int new_height_ok (struct tui_win_info
*, int);
59 static void tui_set_tab_width_command (const char *, int);
60 static void tui_refresh_all_command (const char *, int);
61 static void tui_all_windows_info (const char *, int);
62 static void tui_scroll_forward_command (const char *, int);
63 static void tui_scroll_backward_command (const char *, int);
64 static void tui_scroll_left_command (const char *, int);
65 static void tui_scroll_right_command (const char *, int);
66 static void parse_scrolling_args (const char *,
67 struct tui_win_info
**,
71 #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
72 #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
75 # define ACS_LRCORNER '+'
78 # define ACS_LLCORNER '+'
81 # define ACS_ULCORNER '+'
84 # define ACS_URCORNER '+'
87 # define ACS_HLINE '-'
90 # define ACS_VLINE '|'
93 /* Possible values for tui-border-kind variable. */
94 static const char *const tui_border_kind_enums
[] = {
101 /* Possible values for tui-border-mode and tui-active-border-mode. */
102 static const char *const tui_border_mode_enums
[] = {
119 /* Translation table for border-mode variables.
120 The list of values must be terminated by a NULL.
121 After the NULL value, an entry defines the default. */
122 struct tui_translate tui_border_mode_translate
[] = {
123 { "normal", A_NORMAL
},
124 { "standout", A_STANDOUT
},
125 { "reverse", A_REVERSE
},
127 { "half-standout", A_DIM
| A_STANDOUT
},
129 { "bold-standout", A_BOLD
| A_STANDOUT
},
131 { "normal", A_NORMAL
}
134 /* Translation tables for border-kind, one for each border
135 character (see wborder, border curses operations).
136 -1 is used to indicate the ACS because ACS characters
137 are determined at run time by curses (depends on terminal). */
138 struct tui_translate tui_border_kind_translate_vline
[] = {
146 struct tui_translate tui_border_kind_translate_hline
[] = {
154 struct tui_translate tui_border_kind_translate_ulcorner
[] = {
162 struct tui_translate tui_border_kind_translate_urcorner
[] = {
170 struct tui_translate tui_border_kind_translate_llcorner
[] = {
178 struct tui_translate tui_border_kind_translate_lrcorner
[] = {
187 /* Tui configuration variables controlled with set/show command. */
188 const char *tui_active_border_mode
= "bold-standout";
190 show_tui_active_border_mode (struct ui_file
*file
,
192 struct cmd_list_element
*c
,
195 fprintf_filtered (file
, _("\
196 The attribute mode to use for the active TUI window border is \"%s\".\n"),
200 const char *tui_border_mode
= "normal";
202 show_tui_border_mode (struct ui_file
*file
,
204 struct cmd_list_element
*c
,
207 fprintf_filtered (file
, _("\
208 The attribute mode to use for the TUI window borders is \"%s\".\n"),
212 const char *tui_border_kind
= "acs";
214 show_tui_border_kind (struct ui_file
*file
,
216 struct cmd_list_element
*c
,
219 fprintf_filtered (file
, _("The kind of border for TUI windows is \"%s\".\n"),
224 /* Tui internal configuration variables. These variables are updated
225 by tui_update_variables to reflect the tui configuration
227 chtype tui_border_vline
;
228 chtype tui_border_hline
;
229 chtype tui_border_ulcorner
;
230 chtype tui_border_urcorner
;
231 chtype tui_border_llcorner
;
232 chtype tui_border_lrcorner
;
234 int tui_border_attrs
;
235 int tui_active_border_attrs
;
237 /* Identify the item in the translation table.
238 When the item is not recognized, use the default entry. */
239 static struct tui_translate
*
240 translate (const char *name
, struct tui_translate
*table
)
244 if (name
&& strcmp (table
->name
, name
) == 0)
249 /* Not found, return default entry. */
254 /* Update the tui internal configuration according to gdb settings.
255 Returns 1 if the configuration has changed and the screen should
258 tui_update_variables (void)
261 struct tui_translate
*entry
;
263 entry
= translate (tui_border_mode
, tui_border_mode_translate
);
264 if (tui_border_attrs
!= entry
->value
)
266 tui_border_attrs
= entry
->value
;
269 entry
= translate (tui_active_border_mode
, tui_border_mode_translate
);
270 if (tui_active_border_attrs
!= entry
->value
)
272 tui_active_border_attrs
= entry
->value
;
276 /* If one corner changes, all characters are changed.
277 Only check the first one. The ACS characters are determined at
278 run time by curses terminal management. */
279 entry
= translate (tui_border_kind
, tui_border_kind_translate_lrcorner
);
280 if (tui_border_lrcorner
!= (chtype
) entry
->value
)
282 tui_border_lrcorner
= (entry
->value
< 0) ? ACS_LRCORNER
: entry
->value
;
285 entry
= translate (tui_border_kind
, tui_border_kind_translate_llcorner
);
286 tui_border_llcorner
= (entry
->value
< 0) ? ACS_LLCORNER
: entry
->value
;
288 entry
= translate (tui_border_kind
, tui_border_kind_translate_ulcorner
);
289 tui_border_ulcorner
= (entry
->value
< 0) ? ACS_ULCORNER
: entry
->value
;
291 entry
= translate (tui_border_kind
, tui_border_kind_translate_urcorner
);
292 tui_border_urcorner
= (entry
->value
< 0) ? ACS_URCORNER
: entry
->value
;
294 entry
= translate (tui_border_kind
, tui_border_kind_translate_hline
);
295 tui_border_hline
= (entry
->value
< 0) ? ACS_HLINE
: entry
->value
;
297 entry
= translate (tui_border_kind
, tui_border_kind_translate_vline
);
298 tui_border_vline
= (entry
->value
< 0) ? ACS_VLINE
: entry
->value
;
304 set_tui_cmd (const char *args
, int from_tty
)
309 show_tui_cmd (const char *args
, int from_tty
)
313 static struct cmd_list_element
*tuilist
;
316 tui_command (const char *args
, int from_tty
)
318 printf_unfiltered (_("\"tui\" must be followed by the name of a "
320 help_list (tuilist
, "tui ", all_commands
, gdb_stdout
);
323 struct cmd_list_element
**
324 tui_get_cmd_list (void)
327 add_prefix_cmd ("tui", class_tui
, tui_command
,
328 _("Text User Interface commands."),
329 &tuilist
, "tui ", 0, &cmdlist
);
333 /* The set_func hook of "set tui ..." commands that affect the window
334 borders on the TUI display. */
336 tui_set_var_cmd (const char *null_args
,
337 int from_tty
, struct cmd_list_element
*c
)
339 if (tui_update_variables () && tui_active
)
340 tui_rehighlight_all ();
343 /* Generic window name completion function. Complete window name pointed
344 to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
345 window names 'next' and 'prev' will also be considered as possible
346 completions of the window name. */
349 window_name_completer (completion_tracker
&tracker
,
350 int include_next_prev_p
,
351 const char *text
, const char *word
)
353 std::vector
<const char *> completion_name_vec
;
355 for (tui_win_info
*win_info
: all_tui_windows ())
357 const char *completion_name
= NULL
;
359 /* We can't focus on an invisible window. */
360 if (!win_info
->is_visible ())
363 completion_name
= win_info
->name ();
364 gdb_assert (completion_name
!= NULL
);
365 completion_name_vec
.push_back (completion_name
);
368 /* If no windows are considered visible then the TUI has not yet been
369 initialized. But still "focus src" and "focus cmd" will work because
370 invoking the focus command will entail initializing the TUI which sets the
371 default layout to SRC_COMMAND. */
372 if (completion_name_vec
.empty ())
374 completion_name_vec
.push_back (SRC_NAME
);
375 completion_name_vec
.push_back (CMD_NAME
);
378 if (include_next_prev_p
)
380 completion_name_vec
.push_back ("next");
381 completion_name_vec
.push_back ("prev");
385 completion_name_vec
.push_back (NULL
);
386 complete_on_enum (tracker
, completion_name_vec
.data (), text
, word
);
389 /* Complete possible window names to focus on. TEXT is the complete text
390 entered so far, WORD is the word currently being completed. */
393 focus_completer (struct cmd_list_element
*ignore
,
394 completion_tracker
&tracker
,
395 const char *text
, const char *word
)
397 window_name_completer (tracker
, 1, text
, word
);
400 /* Complete possible window names for winheight command. TEXT is the
401 complete text entered so far, WORD is the word currently being
405 winheight_completer (struct cmd_list_element
*ignore
,
406 completion_tracker
&tracker
,
407 const char *text
, const char *word
)
409 /* The first word is the window name. That we can complete. Subsequent
410 words can't be completed. */
414 window_name_completer (tracker
, 0, text
, word
);
417 /* Update gdb's knowledge of the terminal size. */
419 tui_update_gdb_sizes (void)
425 width
= TUI_CMD_WIN
->width
;
426 height
= TUI_CMD_WIN
->height
;
430 width
= tui_term_width ();
431 height
= tui_term_height ();
434 set_screen_width_and_height (width
, height
);
438 /* Set the logical focus to win_info. */
440 tui_set_win_focus_to (struct tui_win_info
*win_info
)
442 if (win_info
!= NULL
)
444 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
446 tui_unhighlight_win (win_with_focus
);
447 tui_set_win_with_focus (win_info
);
448 tui_highlight_win (win_info
);
454 tui_win_info::forward_scroll (int num_to_scroll
)
456 if (num_to_scroll
== 0)
457 num_to_scroll
= height
- 3;
459 do_scroll_vertical (num_to_scroll
);
463 tui_win_info::backward_scroll (int num_to_scroll
)
465 if (num_to_scroll
== 0)
466 num_to_scroll
= height
- 3;
468 do_scroll_vertical (-num_to_scroll
);
473 tui_win_info::left_scroll (int num_to_scroll
)
475 if (num_to_scroll
== 0)
478 do_scroll_horizontal (num_to_scroll
);
483 tui_win_info::right_scroll (int num_to_scroll
)
485 if (num_to_scroll
== 0)
488 do_scroll_horizontal (-num_to_scroll
);
493 tui_refresh_all_win (void)
495 clearok (curscr
, TRUE
);
500 tui_rehighlight_all (void)
502 for (tui_win_info
*win_info
: all_tui_windows ())
503 win_info
->check_and_display_highlight_if_needed ();
506 /* Resize all the windows based on the terminal size. This function
507 gets called from within the readline SIGWINCH handler. */
509 tui_resize_all (void)
511 int height_diff
, width_diff
;
512 int screenheight
, screenwidth
;
514 rl_get_screen_size (&screenheight
, &screenwidth
);
515 width_diff
= screenwidth
- tui_term_width ();
516 height_diff
= screenheight
- tui_term_height ();
517 if (height_diff
|| width_diff
)
519 enum tui_layout_type cur_layout
= tui_current_layout ();
520 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
521 struct tui_win_info
*first_win
;
522 struct tui_win_info
*second_win
;
523 tui_source_window_base
*src_win
;
524 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
525 int new_height
, split_diff
, cmd_split_diff
, num_wins_displayed
= 2;
527 #ifdef HAVE_RESIZE_TERM
528 resize_term (screenheight
, screenwidth
);
530 /* Turn keypad off while we resize. */
531 if (win_with_focus
!= TUI_CMD_WIN
)
532 keypad (TUI_CMD_WIN
->handle
.get (), FALSE
);
533 tui_update_gdb_sizes ();
534 tui_set_term_height_to (screenheight
);
535 tui_set_term_width_to (screenwidth
);
536 if (cur_layout
== SRC_DISASSEM_COMMAND
537 || cur_layout
== SRC_DATA_COMMAND
538 || cur_layout
== DISASSEM_DATA_COMMAND
)
539 num_wins_displayed
++;
540 split_diff
= height_diff
/ num_wins_displayed
;
541 cmd_split_diff
= split_diff
;
542 if (height_diff
% num_wins_displayed
)
549 /* Now adjust each window. */
550 /* erase + clearok are used instead of a straightforward clear as
551 AIX 5.3 does not define clear. */
553 clearok (curscr
, TRUE
);
557 case DISASSEM_COMMAND
:
558 src_win
= *(tui_source_windows ().begin ());
559 /* Check for invalid heights. */
560 if (height_diff
== 0)
561 new_height
= src_win
->height
;
562 else if ((src_win
->height
+ split_diff
) >=
563 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
564 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
565 else if ((src_win
->height
+ split_diff
) <= 0)
566 new_height
= MIN_WIN_HEIGHT
;
568 new_height
= src_win
->height
+ split_diff
;
570 src_win
->resize (new_height
, screenwidth
, 0, 0);
572 locator
->resize (1, screenwidth
, 0, new_height
);
574 new_height
= screenheight
- (new_height
+ 1);
575 TUI_CMD_WIN
->resize (new_height
, screenwidth
,
576 0, locator
->origin
.y
+ 1);
579 if (cur_layout
== SRC_DISASSEM_COMMAND
)
581 src_win
= TUI_SRC_WIN
;
583 second_win
= TUI_DISASM_WIN
;
587 first_win
= TUI_DATA_WIN
;
588 src_win
= *(tui_source_windows ().begin ());
589 second_win
= src_win
;
591 /* Change the first window's height/width. */
592 /* Check for invalid heights. */
593 if (height_diff
== 0)
594 new_height
= first_win
->height
;
595 else if ((first_win
->height
+
596 second_win
->height
+ (split_diff
* 2)) >=
597 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
598 new_height
= (screenheight
- MIN_CMD_WIN_HEIGHT
- 1) / 2;
599 else if ((first_win
->height
+ split_diff
) <= 0)
600 new_height
= MIN_WIN_HEIGHT
;
602 new_height
= first_win
->height
+ split_diff
;
604 first_win
->resize (new_height
, screenwidth
, 0, 0);
606 /* Change the second window's height/width. */
607 /* Check for invalid heights. */
608 if (height_diff
== 0)
609 new_height
= second_win
->height
;
610 else if ((first_win
->height
+
611 second_win
->height
+ (split_diff
* 2)) >=
612 (screenheight
- MIN_CMD_WIN_HEIGHT
- 1))
614 new_height
= screenheight
- MIN_CMD_WIN_HEIGHT
- 1;
616 new_height
= (new_height
/ 2) + 1;
620 else if ((second_win
->height
+ split_diff
) <= 0)
621 new_height
= MIN_WIN_HEIGHT
;
623 new_height
= second_win
->height
+ split_diff
;
625 second_win
->resize (new_height
, screenwidth
,
626 0, first_win
->height
- 1);
628 locator
->resize (1, screenwidth
,
629 0, second_win
->origin
.y
+ new_height
);
631 /* Change the command window's height/width. */
632 new_height
= screenheight
- (locator
->origin
.y
+ 1);
633 TUI_CMD_WIN
->resize (new_height
, screenwidth
,
634 0, locator
->origin
.y
+ 1);
638 tui_delete_invisible_windows ();
639 /* Turn keypad back on, unless focus is in the command
641 if (win_with_focus
!= TUI_CMD_WIN
)
642 keypad (TUI_CMD_WIN
->handle
.get (), TRUE
);
647 /* Token for use by TUI's asynchronous SIGWINCH handler. */
648 static struct async_signal_handler
*tui_sigwinch_token
;
650 /* TUI's SIGWINCH signal handler. */
652 tui_sigwinch_handler (int signal
)
654 mark_async_signal_handler (tui_sigwinch_token
);
655 tui_set_win_resized_to (true);
658 /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
660 tui_async_resize_screen (gdb_client_data arg
)
662 rl_resize_terminal ();
666 int screen_height
, screen_width
;
668 rl_get_screen_size (&screen_height
, &screen_width
);
669 set_screen_width_and_height (screen_width
, screen_height
);
671 /* win_resized is left set so that the next call to tui_enable()
672 resizes the TUI windows. */
676 tui_set_win_resized_to (false);
678 tui_refresh_all_win ();
679 tui_update_gdb_sizes ();
680 tui_redisplay_readline ();
685 /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
686 uninstalled when we exit TUI, so the handler should not assume that TUI is
689 tui_initialize_win (void)
693 = create_async_signal_handler (tui_async_resize_screen
, NULL
);
696 #ifdef HAVE_SIGACTION
697 struct sigaction old_winch
;
699 memset (&old_winch
, 0, sizeof (old_winch
));
700 old_winch
.sa_handler
= &tui_sigwinch_handler
;
702 old_winch
.sa_flags
= SA_RESTART
;
704 sigaction (SIGWINCH
, &old_winch
, NULL
);
706 signal (SIGWINCH
, &tui_sigwinch_handler
);
714 tui_scroll_forward_command (const char *arg
, int from_tty
)
716 int num_to_scroll
= 1;
717 struct tui_win_info
*win_to_scroll
;
719 /* Make sure the curses mode is enabled. */
722 parse_scrolling_args (arg
, &win_to_scroll
, NULL
);
724 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
725 win_to_scroll
->forward_scroll (num_to_scroll
);
730 tui_scroll_backward_command (const char *arg
, int from_tty
)
732 int num_to_scroll
= 1;
733 struct tui_win_info
*win_to_scroll
;
735 /* Make sure the curses mode is enabled. */
738 parse_scrolling_args (arg
, &win_to_scroll
, NULL
);
740 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
741 win_to_scroll
->backward_scroll (num_to_scroll
);
746 tui_scroll_left_command (const char *arg
, int from_tty
)
749 struct tui_win_info
*win_to_scroll
;
751 /* Make sure the curses mode is enabled. */
753 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
754 win_to_scroll
->left_scroll (num_to_scroll
);
759 tui_scroll_right_command (const char *arg
, int from_tty
)
762 struct tui_win_info
*win_to_scroll
;
764 /* Make sure the curses mode is enabled. */
766 parse_scrolling_args (arg
, &win_to_scroll
, &num_to_scroll
);
767 win_to_scroll
->right_scroll (num_to_scroll
);
771 /* Set focus to the window named by 'arg'. */
773 tui_set_focus_command (const char *arg
, int from_tty
)
779 struct tui_win_info
*win_info
= NULL
;
781 if (subset_compare (arg
, "next"))
782 win_info
= tui_next_win (tui_win_with_focus ());
783 else if (subset_compare (arg
, "prev"))
784 win_info
= tui_prev_win (tui_win_with_focus ());
786 win_info
= tui_partial_win_by_name (arg
);
788 if (win_info
== NULL
)
789 error (_("Unrecognized window name \"%s\""), arg
);
790 if (!win_info
->is_visible ())
791 error (_("Window \"%s\" is not visible"), arg
);
793 tui_set_win_focus_to (win_info
);
794 keypad (TUI_CMD_WIN
->handle
.get (), win_info
!= TUI_CMD_WIN
);
795 printf_filtered (_("Focus set to %s window.\n"),
796 tui_win_with_focus ()->name ());
799 error (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE
);
803 tui_all_windows_info (const char *arg
, int from_tty
)
805 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
806 struct ui_out
*uiout
= current_uiout
;
808 ui_out_emit_table
table_emitter (uiout
, 3, -1, "tui-windows");
809 uiout
->table_header (10, ui_left
, "name", "Name");
810 uiout
->table_header (5, ui_right
, "lines", "Lines");
811 uiout
->table_header (10, ui_left
, "focus", "Focus");
812 uiout
->table_body ();
814 for (tui_win_info
*win_info
: all_tui_windows ())
815 if (win_info
->is_visible ())
817 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
819 uiout
->field_string ("name", win_info
->name ());
820 uiout
->field_signed ("lines", win_info
->height
);
821 if (win_with_focus
== win_info
)
822 uiout
->field_string ("focus", _("(has focus)"));
824 uiout
->field_skip ("focus");
831 tui_refresh_all_command (const char *arg
, int from_tty
)
833 /* Make sure the curses mode is enabled. */
836 tui_refresh_all_win ();
839 /* The tab width that should be used by the TUI. */
841 unsigned int tui_tab_width
= DEFAULT_TAB_LEN
;
843 /* The tab width as set by the user. */
845 static unsigned int internal_tab_width
= DEFAULT_TAB_LEN
;
847 /* After the tab width is set, call this to update the relevant
853 for (tui_win_info
*win_info
: all_tui_windows ())
855 if (win_info
->is_visible ())
856 win_info
->update_tab_width ();
860 /* Callback for "set tui tab-width". */
863 tui_set_tab_width (const char *ignore
,
864 int from_tty
, struct cmd_list_element
*c
)
866 if (internal_tab_width
== 0)
868 internal_tab_width
= tui_tab_width
;
869 error (_("Tab width must not be 0"));
872 tui_tab_width
= internal_tab_width
;
876 /* Callback for "show tui tab-width". */
879 tui_show_tab_width (struct ui_file
*file
, int from_tty
,
880 struct cmd_list_element
*c
, const char *value
)
882 fprintf_filtered (gdb_stdout
, _("TUI tab width is %s spaces.\n"), value
);
886 /* Set the tab width of the specified window. */
888 tui_set_tab_width_command (const char *arg
, int from_tty
)
890 /* Make sure the curses mode is enabled. */
898 warning (_("Tab widths greater than 0 must be specified."));
901 internal_tab_width
= ts
;
910 /* Set the height of the specified window. */
912 tui_set_win_height_command (const char *arg
, int from_tty
)
914 /* Make sure the curses mode is enabled. */
918 std::string copy
= arg
;
919 char *buf
= ©
[0];
923 struct tui_win_info
*win_info
;
926 buf_ptr
= strchr (buf_ptr
, ' ');
931 /* Validate the window name. */
932 win_info
= tui_partial_win_by_name (wname
);
934 if (win_info
== NULL
)
935 error (_("Unrecognized window name \"%s\""), arg
);
936 if (!win_info
->is_visible ())
937 error (_("Window \"%s\" is not visible"), arg
);
939 /* Process the size. */
940 buf_ptr
= skip_spaces (buf_ptr
);
942 if (*buf_ptr
!= '\0')
945 bool fixed_size
= true;
948 if (*buf_ptr
== '+' || *buf_ptr
== '-')
955 input_no
= atoi (buf_ptr
);
961 new_height
= input_no
;
963 new_height
= win_info
->height
+ input_no
;
965 /* Now change the window's height, and adjust
966 all other windows around it. */
967 if (tui_adjust_win_heights (win_info
,
968 new_height
) == TUI_FAILURE
)
969 warning (_("Invalid window height specified.\n%s"),
972 tui_update_gdb_sizes ();
975 warning (_("Invalid window height specified.\n%s"),
980 printf_filtered (WIN_HEIGHT_USAGE
);
983 printf_filtered (WIN_HEIGHT_USAGE
);
986 /* Function to adjust all window heights around the primary. */
987 static enum tui_status
988 tui_adjust_win_heights (struct tui_win_info
*primary_win_info
,
991 enum tui_status status
= TUI_FAILURE
;
993 if (new_height_ok (primary_win_info
, new_height
))
995 status
= TUI_SUCCESS
;
996 if (new_height
!= primary_win_info
->height
)
999 struct tui_win_info
*win_info
;
1000 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
1001 enum tui_layout_type cur_layout
= tui_current_layout ();
1002 int width
= tui_term_width ();
1004 diff
= (new_height
- primary_win_info
->height
) * (-1);
1005 if (cur_layout
== SRC_COMMAND
1006 || cur_layout
== DISASSEM_COMMAND
)
1008 struct tui_win_info
*src_win_info
;
1010 primary_win_info
->resize (new_height
, width
,
1011 0, primary_win_info
->origin
.y
);
1012 if (primary_win_info
->type
== CMD_WIN
)
1014 win_info
= *(tui_source_windows ().begin ());
1015 src_win_info
= win_info
;
1019 win_info
= tui_win_list
[CMD_WIN
];
1020 src_win_info
= primary_win_info
;
1022 win_info
->resize (win_info
->height
+ diff
, width
,
1023 0, win_info
->origin
.y
);
1024 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1025 if ((src_win_info
->type
== SRC_WIN
1026 || src_win_info
->type
== DISASSEM_WIN
))
1028 tui_source_window_base
*src_base
1029 = (tui_source_window_base
*) src_win_info
;
1030 if (src_base
->content
.empty ())
1031 src_base
->erase_source_content ();
1036 struct tui_win_info
*first_win
;
1037 struct tui_source_window_base
*second_win
;
1038 tui_source_window_base
*src1
;
1040 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1044 second_win
= TUI_DISASM_WIN
;
1049 first_win
= TUI_DATA_WIN
;
1050 second_win
= *(tui_source_windows ().begin ());
1052 if (primary_win_info
== TUI_CMD_WIN
)
1053 { /* Split the change in height across the 1st & 2nd
1054 windows, adjusting them as well. */
1055 /* Subtract the locator. */
1056 int first_split_diff
= diff
/ 2;
1057 int second_split_diff
= first_split_diff
;
1061 if (first_win
->height
>
1070 second_split_diff
--;
1072 second_split_diff
++;
1075 /* Make sure that the minimum heights are
1077 while ((first_win
->height
+ first_split_diff
) < 3)
1080 second_split_diff
--;
1082 while ((second_win
->height
+ second_split_diff
) < 3)
1084 second_split_diff
++;
1087 first_win
->resize (first_win
->height
+ first_split_diff
,
1089 0, first_win
->origin
.y
);
1090 second_win
->resize (second_win
->height
+ second_split_diff
,
1092 0, first_win
->height
- 1);
1093 locator
->resize (1, width
,
1094 0, (second_win
->origin
.y
1095 + second_win
->height
+ 1));
1097 TUI_CMD_WIN
->resize (new_height
, width
,
1098 0, locator
->origin
.y
+ 1);
1102 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1103 { /* If there is no way to increase the command
1104 window take real estate from the 1st or 2nd
1106 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1110 for (i
= TUI_CMD_WIN
->height
+ diff
;
1112 if (primary_win_info
== first_win
)
1113 second_win
->height
--;
1115 first_win
->height
--;
1118 if (primary_win_info
== first_win
)
1119 first_win
->resize (new_height
, width
, 0, 0);
1121 first_win
->resize (first_win
->height
, width
, 0, 0);
1122 second_win
->origin
.y
= first_win
->height
- 1;
1123 if (primary_win_info
== second_win
)
1124 second_win
->resize (new_height
, width
,
1125 0, first_win
->height
- 1);
1127 second_win
->resize (second_win
->height
, width
,
1128 0, first_win
->height
- 1);
1129 locator
->resize (1, width
,
1130 0, (second_win
->origin
.y
1131 + second_win
->height
+ 1));
1132 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1133 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1134 TUI_CMD_WIN
->resize (1, width
, 0, locator
->origin
.y
+ 1);
1136 TUI_CMD_WIN
->resize (TUI_CMD_WIN
->height
+ diff
, width
,
1137 0, locator
->origin
.y
+ 1);
1139 if (src1
!= nullptr && src1
->content
.empty ())
1140 src1
->erase_source_content ();
1141 if (second_win
->content
.empty ())
1142 second_win
->erase_source_content ();
1150 /* See tui-data.h. */
1153 tui_win_info::max_height () const
1155 return tui_term_height () - 2;
1159 new_height_ok (struct tui_win_info
*primary_win_info
,
1162 int ok
= (new_height
< tui_term_height ());
1167 enum tui_layout_type cur_layout
= tui_current_layout ();
1169 diff
= (new_height
- primary_win_info
->height
) * (-1);
1170 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1172 ok
= (new_height
<= primary_win_info
->max_height ()
1173 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1175 { /* Check the total height. */
1176 struct tui_win_info
*win_info
;
1178 if (primary_win_info
== TUI_CMD_WIN
)
1179 win_info
= *(tui_source_windows ().begin ());
1181 win_info
= TUI_CMD_WIN
;
1183 (win_info
->height
+ diff
)) <= tui_term_height ());
1188 int cur_total_height
, total_height
, min_height
= 0;
1189 struct tui_win_info
*first_win
;
1190 struct tui_win_info
*second_win
;
1192 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1194 first_win
= TUI_SRC_WIN
;
1195 second_win
= TUI_DISASM_WIN
;
1199 first_win
= TUI_DATA_WIN
;
1200 second_win
= *(tui_source_windows ().begin ());
1202 /* We could simply add all the heights to obtain the same
1203 result but below is more explicit since we subtract 1 for
1204 the line that the first and second windows share, and add
1205 one for the locator. */
1206 total_height
= cur_total_height
=
1207 (first_win
->height
+ second_win
->height
- 1)
1208 + TUI_CMD_WIN
->height
+ 1; /* Locator. */
1209 if (primary_win_info
== TUI_CMD_WIN
)
1211 /* Locator included since first & second win share a line. */
1212 ok
= ((first_win
->height
+
1213 second_win
->height
+ diff
) >=
1214 (MIN_WIN_HEIGHT
* 2)
1215 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1218 total_height
= new_height
+
1219 (first_win
->height
+
1220 second_win
->height
+ diff
);
1221 min_height
= MIN_CMD_WIN_HEIGHT
;
1226 min_height
= MIN_WIN_HEIGHT
;
1228 /* First see if we can increase/decrease the command
1229 window. And make sure that the command window is at
1231 ok
= ((TUI_CMD_WIN
->height
+ diff
) > 0);
1233 { /* Looks like we have to increase/decrease one of
1234 the other windows. */
1235 if (primary_win_info
== first_win
)
1236 ok
= (second_win
->height
+ diff
) >= min_height
;
1238 ok
= (first_win
->height
+ diff
) >= min_height
;
1242 if (primary_win_info
== first_win
)
1243 total_height
= new_height
+
1244 second_win
->height
+
1245 TUI_CMD_WIN
->height
+ diff
;
1247 total_height
= new_height
+
1249 TUI_CMD_WIN
->height
+ diff
;
1252 /* Now make sure that the proposed total height doesn't
1253 exceed the old total height. */
1255 ok
= (new_height
>= min_height
1256 && total_height
<= cur_total_height
);
1265 parse_scrolling_args (const char *arg
,
1266 struct tui_win_info
**win_to_scroll
,
1271 *win_to_scroll
= tui_win_with_focus ();
1273 /* First set up the default window to scroll, in case there is no
1279 /* Process the number of lines to scroll. */
1280 std::string copy
= arg
;
1282 if (isdigit (*buf_ptr
))
1287 buf_ptr
= strchr (buf_ptr
, ' ');
1288 if (buf_ptr
!= NULL
)
1292 *num_to_scroll
= atoi (num_str
);
1295 else if (num_to_scroll
)
1296 *num_to_scroll
= atoi (num_str
);
1299 /* Process the window name if one is specified. */
1300 if (buf_ptr
!= NULL
)
1304 wname
= skip_spaces (buf_ptr
);
1308 *win_to_scroll
= tui_partial_win_by_name (wname
);
1310 if (*win_to_scroll
== NULL
)
1311 error (_("Unrecognized window `%s'"), wname
);
1312 if (!(*win_to_scroll
)->is_visible ())
1313 error (_("Window is not visible"));
1314 else if (*win_to_scroll
== TUI_CMD_WIN
)
1315 *win_to_scroll
= *(tui_source_windows ().begin ());
1321 /* Function to initialize gdb commands, for tui window
1325 _initialize_tui_win (void)
1327 static struct cmd_list_element
*tui_setlist
;
1328 static struct cmd_list_element
*tui_showlist
;
1329 struct cmd_list_element
*cmd
;
1331 /* Define the classes of commands.
1332 They will appear in the help list in the reverse of this order. */
1333 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
1334 _("TUI configuration variables."),
1335 &tui_setlist
, "set tui ",
1336 0 /* allow-unknown */, &setlist
);
1337 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
1338 _("TUI configuration variables."),
1339 &tui_showlist
, "show tui ",
1340 0 /* allow-unknown */, &showlist
);
1342 add_com ("refresh", class_tui
, tui_refresh_all_command
,
1343 _("Refresh the terminal display."));
1345 cmd
= add_com ("tabset", class_tui
, tui_set_tab_width_command
, _("\
1346 Set the width (in characters) of tab stops.\n\
1348 deprecate_cmd (cmd
, "set tui tab-width");
1350 cmd
= add_com ("winheight", class_tui
, tui_set_win_height_command
, _("\
1351 Set or modify the height of a specified window.\n"
1353 "Window names are:\n\
1354 src : the source window\n\
1355 cmd : the command window\n\
1356 asm : the disassembly window\n\
1357 regs : the register display"));
1358 add_com_alias ("wh", "winheight", class_tui
, 0);
1359 set_cmd_completer (cmd
, winheight_completer
);
1360 add_info ("win", tui_all_windows_info
,
1361 _("List of all displayed windows."));
1362 cmd
= add_com ("focus", class_tui
, tui_set_focus_command
, _("\
1363 Set focus to named window or next/prev window.\n"
1365 "Valid Window names are:\n\
1366 src : the source window\n\
1367 asm : the disassembly window\n\
1368 regs : the register display\n\
1369 cmd : the command window"));
1370 add_com_alias ("fs", "focus", class_tui
, 0);
1371 set_cmd_completer (cmd
, focus_completer
);
1372 add_com ("+", class_tui
, tui_scroll_forward_command
, _("\
1373 Scroll window forward.\n\
1374 Usage: + [WIN] [N]"));
1375 add_com ("-", class_tui
, tui_scroll_backward_command
, _("\
1376 Scroll window backward.\n\
1377 Usage: - [WIN] [N]"));
1378 add_com ("<", class_tui
, tui_scroll_left_command
, _("\
1379 Scroll window text to the left.\n\
1380 Usage: < [WIN] [N]"));
1381 add_com (">", class_tui
, tui_scroll_right_command
, _("\
1382 Scroll window text to the right.\n\
1383 Usage: > [WIN] [N]"));
1385 /* Define the tui control variables. */
1386 add_setshow_enum_cmd ("border-kind", no_class
, tui_border_kind_enums
,
1387 &tui_border_kind
, _("\
1388 Set the kind of border for TUI windows."), _("\
1389 Show the kind of border for TUI windows."), _("\
1390 This variable controls the border of TUI windows:\n\
1391 space use a white space\n\
1392 ascii use ascii characters + - | for the border\n\
1393 acs use the Alternate Character Set"),
1395 show_tui_border_kind
,
1396 &tui_setlist
, &tui_showlist
);
1398 add_setshow_enum_cmd ("border-mode", no_class
, tui_border_mode_enums
,
1399 &tui_border_mode
, _("\
1400 Set the attribute mode to use for the TUI window borders."), _("\
1401 Show the attribute mode to use for the TUI window borders."), _("\
1402 This variable controls the attributes to use for the window borders:\n\
1403 normal normal display\n\
1404 standout use highlight mode of terminal\n\
1405 reverse use reverse video mode\n\
1406 half use half bright\n\
1407 half-standout use half bright and standout mode\n\
1408 bold use extra bright or bold\n\
1409 bold-standout use extra bright or bold with standout mode"),
1411 show_tui_border_mode
,
1412 &tui_setlist
, &tui_showlist
);
1414 add_setshow_enum_cmd ("active-border-mode", no_class
, tui_border_mode_enums
,
1415 &tui_active_border_mode
, _("\
1416 Set the attribute mode to use for the active TUI window border."), _("\
1417 Show the attribute mode to use for the active TUI window border."), _("\
1418 This variable controls the attributes to use for the active window border:\n\
1419 normal normal display\n\
1420 standout use highlight mode of terminal\n\
1421 reverse use reverse video mode\n\
1422 half use half bright\n\
1423 half-standout use half bright and standout mode\n\
1424 bold use extra bright or bold\n\
1425 bold-standout use extra bright or bold with standout mode"),
1427 show_tui_active_border_mode
,
1428 &tui_setlist
, &tui_showlist
);
1430 add_setshow_zuinteger_cmd ("tab-width", no_class
,
1431 &internal_tab_width
, _("\
1432 Set the tab width, in characters, for the TUI."), _("\
1433 Show the tab witdh, in characters, for the TUI."), _("\
1434 This variable controls how many spaces are used to display a tab character."),
1435 tui_set_tab_width
, tui_show_tab_width
,
1436 &tui_setlist
, &tui_showlist
);