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
, 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
, 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 char *buf_ptr
= xstrdup (arg
);
781 struct tui_win_info
*win_info
= NULL
;
783 for (i
= 0; (i
< strlen (buf_ptr
)); i
++)
784 buf_ptr
[i
] = tolower (arg
[i
]);
786 if (subset_compare (buf_ptr
, "next"))
787 win_info
= tui_next_win (tui_win_with_focus ());
788 else if (subset_compare (buf_ptr
, "prev"))
789 win_info
= tui_prev_win (tui_win_with_focus ());
791 win_info
= tui_partial_win_by_name (buf_ptr
);
793 if (win_info
== NULL
|| !win_info
->is_visible ())
794 warning (_("Invalid window specified. \n\
795 The window name specified must be valid and visible.\n"));
798 tui_set_win_focus_to (win_info
);
799 keypad (TUI_CMD_WIN
->handle
, (win_info
!= TUI_CMD_WIN
));
803 printf_filtered (_("Focus set to %s window.\n"),
804 tui_win_with_focus ()->name ());
807 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE
);
811 tui_all_windows_info (const char *arg
, int from_tty
)
813 struct tui_win_info
*win_with_focus
= tui_win_with_focus ();
814 struct ui_out
*uiout
= current_uiout
;
816 ui_out_emit_table
table_emitter (uiout
, 3, -1, "tui-windows");
817 uiout
->table_header (10, ui_left
, "name", "Name");
818 uiout
->table_header (5, ui_right
, "lines", "Lines");
819 uiout
->table_header (10, ui_left
, "focus", "Focus");
820 uiout
->table_body ();
822 for (tui_win_info
*win_info
: all_tui_windows ())
823 if (win_info
->is_visible ())
825 ui_out_emit_tuple
tuple_emitter (uiout
, nullptr);
827 uiout
->field_string ("name", win_info
->name ());
828 uiout
->field_signed ("lines", win_info
->height
);
829 if (win_with_focus
== win_info
)
830 uiout
->field_string ("focus", _("(has focus)"));
832 uiout
->field_skip ("focus");
839 tui_refresh_all_command (const char *arg
, int from_tty
)
841 /* Make sure the curses mode is enabled. */
844 tui_refresh_all_win ();
847 /* The tab width that should be used by the TUI. */
849 unsigned int tui_tab_width
= DEFAULT_TAB_LEN
;
851 /* The tab width as set by the user. */
853 static unsigned int internal_tab_width
= DEFAULT_TAB_LEN
;
855 /* After the tab width is set, call this to update the relevant
861 for (tui_win_info
*win_info
: all_tui_windows ())
863 if (win_info
->is_visible ())
864 win_info
->update_tab_width ();
868 /* Callback for "set tui tab-width". */
871 tui_set_tab_width (const char *ignore
,
872 int from_tty
, struct cmd_list_element
*c
)
874 if (internal_tab_width
== 0)
876 internal_tab_width
= tui_tab_width
;
877 error (_("Tab width must not be 0"));
880 tui_tab_width
= internal_tab_width
;
884 /* Callback for "show tui tab-width". */
887 tui_show_tab_width (struct ui_file
*file
, int from_tty
,
888 struct cmd_list_element
*c
, const char *value
)
890 fprintf_filtered (gdb_stdout
, _("TUI tab width is %s spaces.\n"), value
);
894 /* Set the tab width of the specified window. */
896 tui_set_tab_width_command (const char *arg
, int from_tty
)
898 /* Make sure the curses mode is enabled. */
906 warning (_("Tab widths greater than 0 must be specified."));
909 internal_tab_width
= ts
;
918 /* Set the height of the specified window. */
920 tui_set_win_height_command (const char *arg
, int from_tty
)
922 /* Make sure the curses mode is enabled. */
926 std::string copy
= arg
;
927 char *buf
= ©
[0];
931 struct tui_win_info
*win_info
;
934 buf_ptr
= strchr (buf_ptr
, ' ');
939 /* Validate the window name. */
940 for (i
= 0; i
< strlen (wname
); i
++)
941 wname
[i
] = tolower (wname
[i
]);
942 win_info
= tui_partial_win_by_name (wname
);
944 if (win_info
== NULL
|| !win_info
->is_visible ())
945 warning (_("Invalid window specified. \n\
946 The window name specified must be valid and visible.\n"));
949 /* Process the size. */
950 while (*(++buf_ptr
) == ' ')
953 if (*buf_ptr
!= (char) 0)
956 int fixed_size
= TRUE
;
959 if (*buf_ptr
== '+' || *buf_ptr
== '-')
966 input_no
= atoi (buf_ptr
);
972 new_height
= input_no
;
974 new_height
= win_info
->height
+ input_no
;
976 /* Now change the window's height, and adjust
977 all other windows around it. */
978 if (tui_adjust_win_heights (win_info
,
979 new_height
) == TUI_FAILURE
)
980 warning (_("Invalid window height specified.\n%s"),
983 tui_update_gdb_sizes ();
986 warning (_("Invalid window height specified.\n%s"),
992 printf_filtered (WIN_HEIGHT_USAGE
);
995 printf_filtered (WIN_HEIGHT_USAGE
);
998 /* Function to adjust all window heights around the primary. */
999 static enum tui_status
1000 tui_adjust_win_heights (struct tui_win_info
*primary_win_info
,
1003 enum tui_status status
= TUI_FAILURE
;
1005 if (new_height_ok (primary_win_info
, new_height
))
1007 status
= TUI_SUCCESS
;
1008 if (new_height
!= primary_win_info
->height
)
1011 struct tui_win_info
*win_info
;
1012 struct tui_locator_window
*locator
= tui_locator_win_info_ptr ();
1013 enum tui_layout_type cur_layout
= tui_current_layout ();
1014 int width
= tui_term_width ();
1016 diff
= (new_height
- primary_win_info
->height
) * (-1);
1017 if (cur_layout
== SRC_COMMAND
1018 || cur_layout
== DISASSEM_COMMAND
)
1020 struct tui_win_info
*src_win_info
;
1022 primary_win_info
->resize (new_height
, width
,
1023 0, primary_win_info
->origin
.y
);
1024 if (primary_win_info
->type
== CMD_WIN
)
1026 win_info
= *(tui_source_windows ().begin ());
1027 src_win_info
= win_info
;
1031 win_info
= tui_win_list
[CMD_WIN
];
1032 src_win_info
= primary_win_info
;
1034 win_info
->resize (win_info
->height
+ diff
, width
,
1035 0, win_info
->origin
.y
);
1036 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1037 if ((src_win_info
->type
== SRC_WIN
1038 || src_win_info
->type
== DISASSEM_WIN
))
1040 tui_source_window_base
*src_base
1041 = (tui_source_window_base
*) src_win_info
;
1042 if (src_base
->content
.empty ())
1043 src_base
->erase_source_content ();
1048 struct tui_win_info
*first_win
;
1049 struct tui_source_window_base
*second_win
;
1050 tui_source_window_base
*src1
;
1052 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1056 second_win
= TUI_DISASM_WIN
;
1061 first_win
= TUI_DATA_WIN
;
1062 second_win
= *(tui_source_windows ().begin ());
1064 if (primary_win_info
== TUI_CMD_WIN
)
1065 { /* Split the change in height accross the 1st & 2nd
1066 windows, adjusting them as well. */
1067 /* Subtract the locator. */
1068 int first_split_diff
= diff
/ 2;
1069 int second_split_diff
= first_split_diff
;
1073 if (first_win
->height
>
1082 second_split_diff
--;
1084 second_split_diff
++;
1087 /* Make sure that the minimum hieghts are
1089 while ((first_win
->height
+ first_split_diff
) < 3)
1092 second_split_diff
--;
1094 while ((second_win
->height
+ second_split_diff
) < 3)
1096 second_split_diff
++;
1099 first_win
->resize (first_win
->height
+ first_split_diff
,
1101 0, first_win
->origin
.y
);
1102 second_win
->resize (second_win
->height
+ second_split_diff
,
1104 0, first_win
->height
- 1);
1105 locator
->resize (1, width
,
1106 0, (second_win
->origin
.y
1107 + second_win
->height
+ 1));
1109 TUI_CMD_WIN
->resize (new_height
, width
,
1110 0, locator
->origin
.y
+ 1);
1114 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1115 { /* If there is no way to increase the command
1116 window take real estate from the 1st or 2nd
1118 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1122 for (i
= TUI_CMD_WIN
->height
+ diff
;
1124 if (primary_win_info
== first_win
)
1125 second_win
->height
--;
1127 first_win
->height
--;
1130 if (primary_win_info
== first_win
)
1131 first_win
->resize (new_height
, width
, 0, 0);
1133 first_win
->resize (first_win
->height
, width
, 0, 0);
1134 second_win
->origin
.y
= first_win
->height
- 1;
1135 if (primary_win_info
== second_win
)
1136 second_win
->resize (new_height
, width
,
1137 0, first_win
->height
- 1);
1139 second_win
->resize (second_win
->height
, width
,
1140 0, first_win
->height
- 1);
1141 locator
->resize (1, width
,
1142 0, (second_win
->origin
.y
1143 + second_win
->height
+ 1));
1144 TUI_CMD_WIN
->origin
.y
= locator
->origin
.y
+ 1;
1145 if ((TUI_CMD_WIN
->height
+ diff
) < 1)
1146 TUI_CMD_WIN
->resize (1, width
, 0, locator
->origin
.y
+ 1);
1148 TUI_CMD_WIN
->resize (TUI_CMD_WIN
->height
+ diff
, width
,
1149 0, locator
->origin
.y
+ 1);
1151 if (src1
!= nullptr && src1
->content
.empty ())
1152 src1
->erase_source_content ();
1153 if (second_win
->content
.empty ())
1154 second_win
->erase_source_content ();
1162 /* See tui-data.h. */
1165 tui_win_info::max_height () const
1167 return tui_term_height () - 2;
1171 new_height_ok (struct tui_win_info
*primary_win_info
,
1174 int ok
= (new_height
< tui_term_height ());
1179 enum tui_layout_type cur_layout
= tui_current_layout ();
1181 diff
= (new_height
- primary_win_info
->height
) * (-1);
1182 if (cur_layout
== SRC_COMMAND
|| cur_layout
== DISASSEM_COMMAND
)
1184 ok
= (new_height
<= primary_win_info
->max_height ()
1185 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1187 { /* Check the total height. */
1188 struct tui_win_info
*win_info
;
1190 if (primary_win_info
== TUI_CMD_WIN
)
1191 win_info
= *(tui_source_windows ().begin ());
1193 win_info
= TUI_CMD_WIN
;
1195 (win_info
->height
+ diff
)) <= tui_term_height ());
1200 int cur_total_height
, total_height
, min_height
= 0;
1201 struct tui_win_info
*first_win
;
1202 struct tui_win_info
*second_win
;
1204 if (cur_layout
== SRC_DISASSEM_COMMAND
)
1206 first_win
= TUI_SRC_WIN
;
1207 second_win
= TUI_DISASM_WIN
;
1211 first_win
= TUI_DATA_WIN
;
1212 second_win
= *(tui_source_windows ().begin ());
1214 /* We could simply add all the heights to obtain the same
1215 result but below is more explicit since we subtract 1 for
1216 the line that the first and second windows share, and add
1217 one for the locator. */
1218 total_height
= cur_total_height
=
1219 (first_win
->height
+ second_win
->height
- 1)
1220 + TUI_CMD_WIN
->height
+ 1; /* Locator. */
1221 if (primary_win_info
== TUI_CMD_WIN
)
1223 /* Locator included since first & second win share a line. */
1224 ok
= ((first_win
->height
+
1225 second_win
->height
+ diff
) >=
1226 (MIN_WIN_HEIGHT
* 2)
1227 && new_height
>= MIN_CMD_WIN_HEIGHT
);
1230 total_height
= new_height
+
1231 (first_win
->height
+
1232 second_win
->height
+ diff
);
1233 min_height
= MIN_CMD_WIN_HEIGHT
;
1238 min_height
= MIN_WIN_HEIGHT
;
1240 /* First see if we can increase/decrease the command
1241 window. And make sure that the command window is at
1243 ok
= ((TUI_CMD_WIN
->height
+ diff
) > 0);
1245 { /* Looks like we have to increase/decrease one of
1246 the other windows. */
1247 if (primary_win_info
== first_win
)
1248 ok
= (second_win
->height
+ diff
) >= min_height
;
1250 ok
= (first_win
->height
+ diff
) >= min_height
;
1254 if (primary_win_info
== first_win
)
1255 total_height
= new_height
+
1256 second_win
->height
+
1257 TUI_CMD_WIN
->height
+ diff
;
1259 total_height
= new_height
+
1261 TUI_CMD_WIN
->height
+ diff
;
1264 /* Now make sure that the proposed total height doesn't
1265 exceed the old total height. */
1267 ok
= (new_height
>= min_height
1268 && total_height
<= cur_total_height
);
1277 parse_scrolling_args (const char *arg
,
1278 struct tui_win_info
**win_to_scroll
,
1283 *win_to_scroll
= tui_win_with_focus ();
1285 /* First set up the default window to scroll, in case there is no
1291 /* Process the number of lines to scroll. */
1292 std::string copy
= arg
;
1294 if (isdigit (*buf_ptr
))
1299 buf_ptr
= strchr (buf_ptr
, ' ');
1300 if (buf_ptr
!= NULL
)
1302 *buf_ptr
= (char) 0;
1304 *num_to_scroll
= atoi (num_str
);
1307 else if (num_to_scroll
)
1308 *num_to_scroll
= atoi (num_str
);
1311 /* Process the window name if one is specified. */
1312 if (buf_ptr
!= NULL
)
1316 if (*buf_ptr
== ' ')
1317 while (*(++buf_ptr
) == ' ')
1320 if (*buf_ptr
!= (char) 0)
1322 /* Validate the window name. */
1323 for (char *p
= buf_ptr
; *p
!= '\0'; p
++)
1331 *win_to_scroll
= tui_partial_win_by_name (wname
);
1333 if (*win_to_scroll
== NULL
)
1334 error (_("Unrecognized window `%s'"), wname
);
1335 if (!(*win_to_scroll
)->is_visible ())
1336 error (_("Window is not visible"));
1337 else if (*win_to_scroll
== TUI_CMD_WIN
)
1338 *win_to_scroll
= *(tui_source_windows ().begin ());
1343 /* Function to initialize gdb commands, for tui window
1347 _initialize_tui_win (void)
1349 static struct cmd_list_element
*tui_setlist
;
1350 static struct cmd_list_element
*tui_showlist
;
1351 struct cmd_list_element
*cmd
;
1353 /* Define the classes of commands.
1354 They will appear in the help list in the reverse of this order. */
1355 add_prefix_cmd ("tui", class_tui
, set_tui_cmd
,
1356 _("TUI configuration variables."),
1357 &tui_setlist
, "set tui ",
1358 0 /* allow-unknown */, &setlist
);
1359 add_prefix_cmd ("tui", class_tui
, show_tui_cmd
,
1360 _("TUI configuration variables."),
1361 &tui_showlist
, "show tui ",
1362 0 /* allow-unknown */, &showlist
);
1364 add_com ("refresh", class_tui
, tui_refresh_all_command
,
1365 _("Refresh the terminal display."));
1367 cmd
= add_com ("tabset", class_tui
, tui_set_tab_width_command
, _("\
1368 Set the width (in characters) of tab stops.\n\
1370 deprecate_cmd (cmd
, "set tui tab-width");
1372 cmd
= add_com ("winheight", class_tui
, tui_set_win_height_command
, _("\
1373 Set or modify the height of a specified window.\n"
1375 "Window names are:\n\
1376 src : the source window\n\
1377 cmd : the command window\n\
1378 asm : the disassembly window\n\
1379 regs : the register display"));
1380 add_com_alias ("wh", "winheight", class_tui
, 0);
1381 set_cmd_completer (cmd
, winheight_completer
);
1382 add_info ("win", tui_all_windows_info
,
1383 _("List of all displayed windows."));
1384 cmd
= add_com ("focus", class_tui
, tui_set_focus_command
, _("\
1385 Set focus to named window or next/prev window.\n"
1387 "Valid Window names are:\n\
1388 src : the source window\n\
1389 asm : the disassembly window\n\
1390 regs : the register display\n\
1391 cmd : the command window"));
1392 add_com_alias ("fs", "focus", class_tui
, 0);
1393 set_cmd_completer (cmd
, focus_completer
);
1394 add_com ("+", class_tui
, tui_scroll_forward_command
, _("\
1395 Scroll window forward.\n\
1396 Usage: + [WIN] [N]"));
1397 add_com ("-", class_tui
, tui_scroll_backward_command
, _("\
1398 Scroll window backward.\n\
1399 Usage: - [WIN] [N]"));
1400 add_com ("<", class_tui
, tui_scroll_left_command
, _("\
1401 Scroll window text to the left.\n\
1402 Usage: < [WIN] [N]"));
1403 add_com (">", class_tui
, tui_scroll_right_command
, _("\
1404 Scroll window text to the right.\n\
1405 Usage: > [WIN] [N]"));
1407 /* Define the tui control variables. */
1408 add_setshow_enum_cmd ("border-kind", no_class
, tui_border_kind_enums
,
1409 &tui_border_kind
, _("\
1410 Set the kind of border for TUI windows."), _("\
1411 Show the kind of border for TUI windows."), _("\
1412 This variable controls the border of TUI windows:\n\
1413 space use a white space\n\
1414 ascii use ascii characters + - | for the border\n\
1415 acs use the Alternate Character Set"),
1417 show_tui_border_kind
,
1418 &tui_setlist
, &tui_showlist
);
1420 add_setshow_enum_cmd ("border-mode", no_class
, tui_border_mode_enums
,
1421 &tui_border_mode
, _("\
1422 Set the attribute mode to use for the TUI window borders."), _("\
1423 Show the attribute mode to use for the TUI window borders."), _("\
1424 This variable controls the attributes to use for the window borders:\n\
1425 normal normal display\n\
1426 standout use highlight mode of terminal\n\
1427 reverse use reverse video mode\n\
1428 half use half bright\n\
1429 half-standout use half bright and standout mode\n\
1430 bold use extra bright or bold\n\
1431 bold-standout use extra bright or bold with standout mode"),
1433 show_tui_border_mode
,
1434 &tui_setlist
, &tui_showlist
);
1436 add_setshow_enum_cmd ("active-border-mode", no_class
, tui_border_mode_enums
,
1437 &tui_active_border_mode
, _("\
1438 Set the attribute mode to use for the active TUI window border."), _("\
1439 Show the attribute mode to use for the active TUI window border."), _("\
1440 This variable controls the attributes to use for the active window border:\n\
1441 normal normal display\n\
1442 standout use highlight mode of terminal\n\
1443 reverse use reverse video mode\n\
1444 half use half bright\n\
1445 half-standout use half bright and standout mode\n\
1446 bold use extra bright or bold\n\
1447 bold-standout use extra bright or bold with standout mode"),
1449 show_tui_active_border_mode
,
1450 &tui_setlist
, &tui_showlist
);
1452 add_setshow_zuinteger_cmd ("tab-width", no_class
,
1453 &internal_tab_width
, _("\
1454 Set the tab width, in characters, for the TUI."), _("\
1455 Show the tab witdh, in characters, for the TUI."), _("\
1456 This variable controls how many spaces are used to display a tab character."),
1457 tui_set_tab_width
, tui_show_tab_width
,
1458 &tui_setlist
, &tui_showlist
);