Use "bool" in tui_data_window::show_register_group
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
CommitLineData
f377b406 1/* TUI window generic functions.
f33c6cbf 2
42a4f53d 3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
f33c6cbf 4
f377b406 5 Contributed by Hewlett-Packard Company.
c906108c 6
f377b406
SC
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
a9762ec7 11 the Free Software Foundation; either version 3 of the License, or
f377b406
SC
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
a9762ec7 20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
f377b406
SC
21
22/* This module contains procedures for handling tui window functions
23 like resize, scrolling, scrolling, changing focus, etc.
24
25 Author: Susan B. Macchia */
c906108c 26
c906108c
SS
27#include "defs.h"
28#include "command.h"
29#include "symtab.h"
30#include "breakpoint.h"
31#include "frame.h"
41783295 32#include "cli/cli-cmds.h"
3e752b04 33#include "top.h"
52575520 34#include "source.h"
c4ef48c6 35#include "event-loop.h"
c906108c 36
d7b2e967 37#include "tui/tui.h"
c4ef48c6 38#include "tui/tui-io.h"
ce38393b 39#include "tui/tui-command.h"
d7b2e967 40#include "tui/tui-data.h"
3df505f6 41#include "tui/tui-layout.h"
d7b2e967
AC
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"
2c0b251b 48#include "tui/tui-win.h"
c906108c 49
6a83354a 50#include "gdb_curses.h"
96ec9981 51#include <ctype.h>
dbda9972 52#include "readline/readline.h"
96ec9981 53
9612b5ec
UW
54#include <signal.h>
55
c906108c
SS
56/*******************************
57** Static Local Decls
58********************************/
08ef48c5
MS
59static enum tui_status tui_adjust_win_heights (struct tui_win_info *,
60 int);
6ba8e26f 61static int new_height_ok (struct tui_win_info *, int);
0b39b52e
TT
62static void tui_set_tab_width_command (const char *, int);
63static void tui_refresh_all_command (const char *, int);
1d12d88f 64static void tui_all_windows_info (const char *, int);
0b39b52e
TT
65static void tui_scroll_forward_command (const char *, int);
66static void tui_scroll_backward_command (const char *, int);
67static void tui_scroll_left_command (const char *, int);
68static void tui_scroll_right_command (const char *, int);
69static void parse_scrolling_args (const char *,
08ef48c5
MS
70 struct tui_win_info **,
71 int *);
c906108c
SS
72
73
74/***************************************
75** DEFINITIONS
76***************************************/
57dbb3af 77#define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
bf212be1 78#define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
c906108c
SS
79
80/***************************************
81** PUBLIC FUNCTIONS
82***************************************/
83
17aae570
SC
84#ifndef ACS_LRCORNER
85# define ACS_LRCORNER '+'
86#endif
87#ifndef ACS_LLCORNER
88# define ACS_LLCORNER '+'
89#endif
90#ifndef ACS_ULCORNER
91# define ACS_ULCORNER '+'
92#endif
93#ifndef ACS_URCORNER
94# define ACS_URCORNER '+'
95#endif
96#ifndef ACS_HLINE
97# define ACS_HLINE '-'
98#endif
99#ifndef ACS_VLINE
100# define ACS_VLINE '|'
101#endif
102
af101512 103/* Possible values for tui-border-kind variable. */
40478521 104static const char *const tui_border_kind_enums[] = {
af101512
SC
105 "space",
106 "ascii",
107 "acs",
108 NULL
109};
110
111/* Possible values for tui-border-mode and tui-active-border-mode. */
40478521 112static const char *const tui_border_mode_enums[] = {
af101512
SC
113 "normal",
114 "standout",
115 "reverse",
116 "half",
117 "half-standout",
118 "bold",
119 "bold-standout",
120 NULL
121};
122
123struct tui_translate
124{
125 const char *name;
126 int value;
127};
128
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. */
132struct tui_translate tui_border_mode_translate[] = {
133 { "normal", A_NORMAL },
134 { "standout", A_STANDOUT },
135 { "reverse", A_REVERSE },
136 { "half", A_DIM },
137 { "half-standout", A_DIM | A_STANDOUT },
138 { "bold", A_BOLD },
139 { "bold-standout", A_BOLD | A_STANDOUT },
140 { 0, 0 },
141 { "normal", A_NORMAL }
142};
143
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). */
148struct tui_translate tui_border_kind_translate_vline[] = {
149 { "space", ' ' },
150 { "ascii", '|' },
151 { "acs", -1 },
152 { 0, 0 },
153 { "ascii", '|' }
154};
155
156struct tui_translate tui_border_kind_translate_hline[] = {
157 { "space", ' ' },
158 { "ascii", '-' },
159 { "acs", -1 },
160 { 0, 0 },
161 { "ascii", '-' }
162};
163
164struct tui_translate tui_border_kind_translate_ulcorner[] = {
165 { "space", ' ' },
166 { "ascii", '+' },
167 { "acs", -1 },
168 { 0, 0 },
169 { "ascii", '+' }
170};
171
172struct tui_translate tui_border_kind_translate_urcorner[] = {
173 { "space", ' ' },
174 { "ascii", '+' },
175 { "acs", -1 },
176 { 0, 0 },
177 { "ascii", '+' }
178};
179
180struct tui_translate tui_border_kind_translate_llcorner[] = {
181 { "space", ' ' },
182 { "ascii", '+' },
183 { "acs", -1 },
184 { 0, 0 },
185 { "ascii", '+' }
186};
187
188struct tui_translate tui_border_kind_translate_lrcorner[] = {
189 { "space", ' ' },
190 { "ascii", '+' },
191 { "acs", -1 },
192 { 0, 0 },
193 { "ascii", '+' }
194};
195
196
197/* Tui configuration variables controlled with set/show command. */
198const char *tui_active_border_mode = "bold-standout";
920d2a44 199static void
08ef48c5
MS
200show_tui_active_border_mode (struct ui_file *file,
201 int from_tty,
202 struct cmd_list_element *c,
203 const char *value)
920d2a44
AC
204{
205 fprintf_filtered (file, _("\
206The attribute mode to use for the active TUI window border is \"%s\".\n"),
207 value);
208}
209
af101512 210const char *tui_border_mode = "normal";
920d2a44 211static void
08ef48c5
MS
212show_tui_border_mode (struct ui_file *file,
213 int from_tty,
214 struct cmd_list_element *c,
215 const char *value)
920d2a44
AC
216{
217 fprintf_filtered (file, _("\
218The attribute mode to use for the TUI window borders is \"%s\".\n"),
219 value);
220}
221
af101512 222const char *tui_border_kind = "acs";
920d2a44 223static void
08ef48c5
MS
224show_tui_border_kind (struct ui_file *file,
225 int from_tty,
226 struct cmd_list_element *c,
227 const char *value)
920d2a44
AC
228{
229 fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
230 value);
231}
232
af101512 233
1cc6d956
MS
234/* Tui internal configuration variables. These variables are updated
235 by tui_update_variables to reflect the tui configuration
af101512
SC
236 variables. */
237chtype tui_border_vline;
238chtype tui_border_hline;
239chtype tui_border_ulcorner;
240chtype tui_border_urcorner;
241chtype tui_border_llcorner;
242chtype tui_border_lrcorner;
243
244int tui_border_attrs;
245int tui_active_border_attrs;
246
247/* Identify the item in the translation table.
248 When the item is not recognized, use the default entry. */
249static struct tui_translate *
250translate (const char *name, struct tui_translate *table)
251{
252 while (table->name)
253 {
254 if (name && strcmp (table->name, name) == 0)
255 return table;
256 table++;
257 }
258
259 /* Not found, return default entry. */
260 table++;
261 return table;
262}
263
264/* Update the tui internal configuration according to gdb settings.
265 Returns 1 if the configuration has changed and the screen should
266 be redrawn. */
267int
d02c80cd 268tui_update_variables (void)
af101512
SC
269{
270 int need_redraw = 0;
271 struct tui_translate *entry;
272
273 entry = translate (tui_border_mode, tui_border_mode_translate);
274 if (tui_border_attrs != entry->value)
275 {
276 tui_border_attrs = entry->value;
277 need_redraw = 1;
278 }
279 entry = translate (tui_active_border_mode, tui_border_mode_translate);
280 if (tui_active_border_attrs != entry->value)
281 {
282 tui_active_border_attrs = entry->value;
283 need_redraw = 1;
284 }
285
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)
291 {
292 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
293 need_redraw = 1;
294 }
295 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
296 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
297
298 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
299 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
300
301 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
302 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
303
304 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
305 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
306
307 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
308 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
309
310 return need_redraw;
311}
312
c9684879 313static void
981a3fb3 314set_tui_cmd (const char *args, int from_tty)
c9684879
SC
315{
316}
317
318static void
981a3fb3 319show_tui_cmd (const char *args, int from_tty)
c9684879
SC
320{
321}
af101512 322
10f59415
SC
323static struct cmd_list_element *tuilist;
324
325static void
981a3fb3 326tui_command (const char *args, int from_tty)
10f59415 327{
a3f17187
AC
328 printf_unfiltered (_("\"tui\" must be followed by the name of a "
329 "tui command.\n"));
635c7e8a 330 help_list (tuilist, "tui ", all_commands, gdb_stdout);
10f59415
SC
331}
332
333struct cmd_list_element **
da745b36 334tui_get_cmd_list (void)
10f59415
SC
335{
336 if (tuilist == 0)
337 add_prefix_cmd ("tui", class_tui, tui_command,
1bedd215 338 _("Text User Interface commands."),
10f59415
SC
339 &tuilist, "tui ", 0, &cmdlist);
340 return &tuilist;
341}
342
6cdb25f4
EZ
343/* The set_func hook of "set tui ..." commands that affect the window
344 borders on the TUI display. */
345void
eb4c3f4a
TT
346tui_set_var_cmd (const char *null_args,
347 int from_tty, struct cmd_list_element *c)
6cdb25f4
EZ
348{
349 if (tui_update_variables () && tui_active)
350 tui_rehighlight_all ();
351}
352
97605e61
AB
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. */
2e52ae68 357
eb3ff9a5
PA
358static void
359window_name_completer (completion_tracker &tracker,
360 int include_next_prev_p,
97605e61 361 const char *text, const char *word)
2e52ae68 362{
625ad440 363 std::vector<const char *> completion_name_vec;
2e52ae68 364
1ce3e844 365 for (tui_win_info *win_info : all_tui_windows ())
2e52ae68
PP
366 {
367 const char *completion_name = NULL;
368
369 /* We can't focus on an invisible window. */
2d83e710 370 if (!win_info->is_visible ())
2e52ae68
PP
371 continue;
372
1ce3e844 373 completion_name = win_info->name ();
150375dc 374 gdb_assert (completion_name != NULL);
625ad440 375 completion_name_vec.push_back (completion_name);
2e52ae68
PP
376 }
377
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. */
625ad440 382 if (completion_name_vec.empty ())
2e52ae68 383 {
625ad440
SM
384 completion_name_vec.push_back (SRC_NAME);
385 completion_name_vec.push_back (CMD_NAME);
2e52ae68
PP
386 }
387
97605e61
AB
388 if (include_next_prev_p)
389 {
625ad440
SM
390 completion_name_vec.push_back ("next");
391 completion_name_vec.push_back ("prev");
97605e61 392 }
2e52ae68 393
2e52ae68 394
625ad440
SM
395 completion_name_vec.push_back (NULL);
396 complete_on_enum (tracker, completion_name_vec.data (), text, word);
2e52ae68
PP
397}
398
97605e61
AB
399/* Complete possible window names to focus on. TEXT is the complete text
400 entered so far, WORD is the word currently being completed. */
401
eb3ff9a5 402static void
97605e61 403focus_completer (struct cmd_list_element *ignore,
eb3ff9a5
PA
404 completion_tracker &tracker,
405 const char *text, const char *word)
97605e61 406{
eb3ff9a5 407 window_name_completer (tracker, 1, text, word);
97605e61
AB
408}
409
410/* Complete possible window names for winheight command. TEXT is the
411 complete text entered so far, WORD is the word currently being
412 completed. */
413
eb3ff9a5 414static void
97605e61 415winheight_completer (struct cmd_list_element *ignore,
eb3ff9a5 416 completion_tracker &tracker,
97605e61
AB
417 const char *text, const char *word)
418{
419 /* The first word is the window name. That we can complete. Subsequent
420 words can't be completed. */
421 if (word != text)
eb3ff9a5 422 return;
97605e61 423
eb3ff9a5 424 window_name_completer (tracker, 0, text, word);
97605e61
AB
425}
426
3e752b04
SC
427/* Update gdb's knowledge of the terminal size. */
428void
d02c80cd 429tui_update_gdb_sizes (void)
3e752b04 430{
d6e5e7f7
PP
431 int width, height;
432
433 if (tui_active)
434 {
cb2ce893
TT
435 width = TUI_CMD_WIN->width;
436 height = TUI_CMD_WIN->height;
d6e5e7f7
PP
437 }
438 else
439 {
440 width = tui_term_width ();
441 height = tui_term_height ();
442 }
443
444 set_screen_width_and_height (width, height);
3e752b04
SC
445}
446
c906108c 447
1cc6d956 448/* Set the logical focus to win_info. */
c906108c 449void
5b6fe301 450tui_set_win_focus_to (struct tui_win_info *win_info)
c906108c 451{
6d012f14 452 if (win_info != NULL)
c906108c 453 {
5b6fe301 454 struct tui_win_info *win_with_focus = tui_win_with_focus ();
c906108c 455
bbc228ee 456 tui_unhighlight_win (win_with_focus);
6d012f14 457 tui_set_win_with_focus (win_info);
bbc228ee 458 tui_highlight_win (win_info);
c906108c 459 }
6ba8e26f 460}
c906108c
SS
461
462
c906108c 463void
13446e05 464tui_win_info::forward_scroll (int num_to_scroll)
c906108c 465{
13446e05 466 if (num_to_scroll == 0)
cb2ce893 467 num_to_scroll = height - 3;
c906108c 468
c3bd716f 469 do_scroll_vertical (num_to_scroll);
a21fcd8f 470}
c906108c 471
c906108c 472void
13446e05 473tui_win_info::backward_scroll (int num_to_scroll)
c906108c 474{
13446e05 475 if (num_to_scroll == 0)
cb2ce893 476 num_to_scroll = height - 3;
13446e05 477
c3bd716f 478 do_scroll_vertical (-num_to_scroll);
a21fcd8f 479}
c906108c
SS
480
481
c906108c 482void
13446e05 483tui_win_info::left_scroll (int num_to_scroll)
c906108c 484{
13446e05
TT
485 if (num_to_scroll == 0)
486 num_to_scroll = 1;
487
c3bd716f 488 do_scroll_horizontal (num_to_scroll);
a21fcd8f 489}
c906108c
SS
490
491
c906108c 492void
13446e05 493tui_win_info::right_scroll (int num_to_scroll)
c906108c 494{
13446e05
TT
495 if (num_to_scroll == 0)
496 num_to_scroll = 1;
497
c3bd716f 498 do_scroll_horizontal (-num_to_scroll);
e8b915dc 499}
c906108c
SS
500
501
c906108c 502void
a21fcd8f 503tui_refresh_all_win (void)
c906108c 504{
3e266828 505 clearok (curscr, TRUE);
1ce3e844 506 tui_refresh_all ();
bc712bbf 507}
c906108c 508
6cdb25f4
EZ
509void
510tui_rehighlight_all (void)
511{
1ce3e844 512 for (tui_win_info *win_info : all_tui_windows ())
b4ef5aeb 513 win_info->check_and_display_highlight_if_needed ();
6cdb25f4 514}
c906108c 515
b021a221 516/* Resize all the windows based on the terminal size. This function
ae2b5380 517 gets called from within the readline SIGWINCH handler. */
c906108c 518void
6ba8e26f 519tui_resize_all (void)
c906108c 520{
6ba8e26f 521 int height_diff, width_diff;
9255ee31 522 int screenheight, screenwidth;
c906108c 523
9255ee31 524 rl_get_screen_size (&screenheight, &screenwidth);
6ba8e26f
AC
525 width_diff = screenwidth - tui_term_width ();
526 height_diff = screenheight - tui_term_height ();
527 if (height_diff || width_diff)
c906108c 528 {
6ba8e26f 529 enum tui_layout_type cur_layout = tui_current_layout ();
5b6fe301 530 struct tui_win_info *win_with_focus = tui_win_with_focus ();
6ba8e26f
AC
531 struct tui_win_info *first_win;
532 struct tui_win_info *second_win;
7908abbf 533 tui_source_window_base *src_win;
3add462f 534 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
6ba8e26f 535 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
c906108c 536
10f59415
SC
537#ifdef HAVE_RESIZE_TERM
538 resize_term (screenheight, screenwidth);
539#endif
1cc6d956 540 /* Turn keypad off while we resize. */
6ba8e26f 541 if (win_with_focus != TUI_CMD_WIN)
cb2ce893 542 keypad (TUI_CMD_WIN->handle, FALSE);
3e752b04 543 tui_update_gdb_sizes ();
dd1abb8c
AC
544 tui_set_term_height_to (screenheight);
545 tui_set_term_width_to (screenwidth);
e5908723
MS
546 if (cur_layout == SRC_DISASSEM_COMMAND
547 || cur_layout == SRC_DATA_COMMAND
548 || cur_layout == DISASSEM_DATA_COMMAND)
6ba8e26f
AC
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)
c906108c 553 {
6ba8e26f
AC
554 if (height_diff < 0)
555 cmd_split_diff--;
c906108c 556 else
c366c1f0
TT
557 cmd_split_diff++;
558 }
1cc6d956 559 /* Now adjust each window. */
c366c1f0
TT
560 /* erase + clearok are used instead of a straightforward clear as
561 AIX 5.3 does not define clear. */
562 erase ();
563 clearok (curscr, TRUE);
c906108c 564 refresh ();
6ba8e26f 565 switch (cur_layout)
c366c1f0 566 {
c906108c
SS
567 case SRC_COMMAND:
568 case DISASSEM_COMMAND:
3891b65e 569 src_win = *(tui_source_windows ().begin ());
1cc6d956 570 /* Check for invalid heights. */
6ba8e26f 571 if (height_diff == 0)
3df505f6
TT
572 new_height = src_win->height;
573 else if ((src_win->height + split_diff) >=
c906108c 574 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
6ba8e26f 575 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
3df505f6 576 else if ((src_win->height + split_diff) <= 0)
6ba8e26f 577 new_height = MIN_WIN_HEIGHT;
c906108c 578 else
3df505f6
TT
579 new_height = src_win->height + split_diff;
580
581 src_win->resize (new_height, screenwidth, 0, 0);
c906108c 582
3df505f6
TT
583 locator->resize (2 /* 1 */, screenwidth,
584 0, new_height);
585
586 new_height = screenheight - (new_height + 1);
587 TUI_CMD_WIN->resize (new_height, screenwidth,
588 0, locator->origin.y + 1);
c906108c
SS
589 break;
590 default:
6ba8e26f 591 if (cur_layout == SRC_DISASSEM_COMMAND)
c906108c 592 {
7908abbf
TT
593 src_win = TUI_SRC_WIN;
594 first_win = src_win;
6ba8e26f 595 second_win = TUI_DISASM_WIN;
c906108c
SS
596 }
597 else
598 {
6ba8e26f 599 first_win = TUI_DATA_WIN;
3891b65e 600 src_win = *(tui_source_windows ().begin ());
7908abbf 601 second_win = src_win;
c906108c 602 }
1cc6d956
MS
603 /* Change the first window's height/width. */
604 /* Check for invalid heights. */
6ba8e26f 605 if (height_diff == 0)
cb2ce893
TT
606 new_height = first_win->height;
607 else if ((first_win->height +
608 second_win->height + (split_diff * 2)) >=
c906108c 609 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
6ba8e26f 610 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
cb2ce893 611 else if ((first_win->height + split_diff) <= 0)
6ba8e26f 612 new_height = MIN_WIN_HEIGHT;
c906108c 613 else
cb2ce893 614 new_height = first_win->height + split_diff;
c906108c 615
3df505f6 616 first_win->resize (new_height, screenwidth, 0, 0);
c906108c 617
1cc6d956
MS
618 /* Change the second window's height/width. */
619 /* Check for invalid heights. */
6ba8e26f 620 if (height_diff == 0)
cb2ce893
TT
621 new_height = second_win->height;
622 else if ((first_win->height +
623 second_win->height + (split_diff * 2)) >=
c906108c
SS
624 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
625 {
6ba8e26f
AC
626 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
627 if (new_height % 2)
628 new_height = (new_height / 2) + 1;
c906108c 629 else
6ba8e26f 630 new_height /= 2;
c906108c 631 }
cb2ce893 632 else if ((second_win->height + split_diff) <= 0)
6ba8e26f 633 new_height = MIN_WIN_HEIGHT;
c906108c 634 else
cb2ce893 635 new_height = second_win->height + split_diff;
3df505f6
TT
636
637 second_win->resize (new_height, screenwidth,
638 0, first_win->height - 1);
639
640 locator->resize (2 /* 1 */, screenwidth,
641 0, second_win->origin.y + new_height);
c906108c 642
1cc6d956 643 /* Change the command window's height/width. */
3df505f6
TT
644 new_height = screenheight - (locator->origin.y + 1);
645 TUI_CMD_WIN->resize (new_height, screenwidth,
646 0, locator->origin.y + 1);
c906108c
SS
647 break;
648 }
fede5273
TT
649
650 tui_delete_invisible_windows ();
1cc6d956
MS
651 /* Turn keypad back on, unless focus is in the command
652 window. */
6ba8e26f 653 if (win_with_focus != TUI_CMD_WIN)
cb2ce893 654 keypad (TUI_CMD_WIN->handle, TRUE);
c906108c 655 }
6ba8e26f 656}
c906108c 657
2c0b251b 658#ifdef SIGWINCH
c4ef48c6
PP
659/* Token for use by TUI's asynchronous SIGWINCH handler. */
660static struct async_signal_handler *tui_sigwinch_token;
661
662/* TUI's SIGWINCH signal handler. */
2c0b251b 663static void
6ba8e26f 664tui_sigwinch_handler (int signal)
c906108c 665{
c4ef48c6 666 mark_async_signal_handler (tui_sigwinch_token);
dd1abb8c 667 tui_set_win_resized_to (TRUE);
6ba8e26f 668}
c4ef48c6
PP
669
670/* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
671static void
672tui_async_resize_screen (gdb_client_data arg)
673{
a88d0bb3
PP
674 rl_resize_terminal ();
675
c4ef48c6 676 if (!tui_active)
a88d0bb3
PP
677 {
678 int screen_height, screen_width;
c4ef48c6 679
a88d0bb3
PP
680 rl_get_screen_size (&screen_height, &screen_width);
681 set_screen_width_and_height (screen_width, screen_height);
682
683 /* win_resized is left set so that the next call to tui_enable()
684 resizes the TUI windows. */
685 }
686 else
687 {
1e04046d 688 tui_set_win_resized_to (FALSE);
a88d0bb3
PP
689 tui_resize_all ();
690 tui_refresh_all_win ();
691 tui_update_gdb_sizes ();
a88d0bb3
PP
692 tui_redisplay_readline ();
693 }
c4ef48c6 694}
2c0b251b 695#endif
c906108c 696
c4ef48c6
PP
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
699 always active. */
9612b5ec
UW
700void
701tui_initialize_win (void)
702{
703#ifdef SIGWINCH
c4ef48c6
PP
704 tui_sigwinch_token
705 = create_async_signal_handler (tui_async_resize_screen, NULL);
706
707 {
9612b5ec 708#ifdef HAVE_SIGACTION
c4ef48c6 709 struct sigaction old_winch;
1c5313c5 710
c4ef48c6
PP
711 memset (&old_winch, 0, sizeof (old_winch));
712 old_winch.sa_handler = &tui_sigwinch_handler;
a344fc09 713#ifdef SA_RESTART
c4ef48c6 714 old_winch.sa_flags = SA_RESTART;
a344fc09 715#endif
c4ef48c6 716 sigaction (SIGWINCH, &old_winch, NULL);
9612b5ec 717#else
c4ef48c6 718 signal (SIGWINCH, &tui_sigwinch_handler);
9612b5ec 719#endif
c4ef48c6 720 }
9612b5ec
UW
721#endif
722}
c906108c
SS
723
724
725/*************************
726** STATIC LOCAL FUNCTIONS
727**************************/
728
729
c906108c 730static void
0b39b52e 731tui_scroll_forward_command (const char *arg, int from_tty)
c906108c 732{
6ba8e26f 733 int num_to_scroll = 1;
5b6fe301 734 struct tui_win_info *win_to_scroll;
c906108c 735
1854bb21
SC
736 /* Make sure the curses mode is enabled. */
737 tui_enable ();
63a33118 738 if (arg == NULL)
cafb3438 739 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 740 else
6ba8e26f 741 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 742 win_to_scroll->forward_scroll (num_to_scroll);
e8b915dc 743}
c906108c
SS
744
745
c906108c 746static void
0b39b52e 747tui_scroll_backward_command (const char *arg, int from_tty)
c906108c 748{
6ba8e26f 749 int num_to_scroll = 1;
5b6fe301 750 struct tui_win_info *win_to_scroll;
c906108c 751
1854bb21
SC
752 /* Make sure the curses mode is enabled. */
753 tui_enable ();
63a33118 754 if (arg == NULL)
cafb3438 755 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 756 else
6ba8e26f 757 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 758 win_to_scroll->backward_scroll (num_to_scroll);
e8b915dc 759}
c906108c
SS
760
761
c906108c 762static void
0b39b52e 763tui_scroll_left_command (const char *arg, int from_tty)
c906108c 764{
6ba8e26f 765 int num_to_scroll;
5b6fe301 766 struct tui_win_info *win_to_scroll;
c906108c 767
1854bb21
SC
768 /* Make sure the curses mode is enabled. */
769 tui_enable ();
6ba8e26f 770 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 771 win_to_scroll->left_scroll (num_to_scroll);
e8b915dc 772}
c906108c
SS
773
774
c906108c 775static void
0b39b52e 776tui_scroll_right_command (const char *arg, int from_tty)
c906108c 777{
6ba8e26f 778 int num_to_scroll;
5b6fe301 779 struct tui_win_info *win_to_scroll;
c906108c 780
1854bb21
SC
781 /* Make sure the curses mode is enabled. */
782 tui_enable ();
6ba8e26f 783 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 784 win_to_scroll->right_scroll (num_to_scroll);
e8b915dc 785}
c906108c
SS
786
787
6ba8e26f 788/* Set focus to the window named by 'arg'. */
c906108c 789static void
01aeb396 790tui_set_focus_command (const char *arg, int from_tty)
c906108c 791{
01aeb396
TT
792 tui_enable ();
793
63a33118 794 if (arg != NULL)
c906108c 795 {
63a33118 796 char *buf_ptr = xstrdup (arg);
c906108c 797 int i;
e65b5245 798 struct tui_win_info *win_info = NULL;
c906108c 799
6ba8e26f 800 for (i = 0; (i < strlen (buf_ptr)); i++)
6dce28e4 801 buf_ptr[i] = tolower (arg[i]);
c906108c 802
6dce28e4 803 if (subset_compare (buf_ptr, "next"))
6d012f14 804 win_info = tui_next_win (tui_win_with_focus ());
6dce28e4 805 else if (subset_compare (buf_ptr, "prev"))
6d012f14 806 win_info = tui_prev_win (tui_win_with_focus ());
c906108c 807 else
6ba8e26f 808 win_info = tui_partial_win_by_name (buf_ptr);
c906108c 809
2d83e710 810 if (win_info == NULL || !win_info->is_visible ())
8a3fe4f8
AC
811 warning (_("Invalid window specified. \n\
812The window name specified must be valid and visible.\n"));
c906108c
SS
813 else
814 {
6d012f14 815 tui_set_win_focus_to (win_info);
cb2ce893 816 keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
c906108c
SS
817 }
818
6ba8e26f 819 xfree (buf_ptr);
a3f17187 820 printf_filtered (_("Focus set to %s window.\n"),
152f3f4b 821 tui_win_with_focus ()->name ());
c906108c
SS
822 }
823 else
8a3fe4f8 824 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
6ba8e26f 825}
c906108c 826
c906108c 827static void
1d12d88f 828tui_all_windows_info (const char *arg, int from_tty)
c906108c 829{
5b6fe301 830 struct tui_win_info *win_with_focus = tui_win_with_focus ();
25a2915e
TT
831 struct ui_out *uiout = current_uiout;
832
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 ();
c906108c 838
1ce3e844 839 for (tui_win_info *win_info : all_tui_windows ())
2d83e710 840 if (win_info->is_visible ())
c906108c 841 {
25a2915e
TT
842 ui_out_emit_tuple tuple_emitter (uiout, nullptr);
843
844 uiout->field_string ("name", win_info->name ());
845 uiout->field_signed ("lines", win_info->height);
1ce3e844 846 if (win_with_focus == win_info)
25a2915e 847 uiout->field_string ("focus", _("(has focus)"));
c906108c 848 else
25a2915e
TT
849 uiout->field_skip ("focus");
850 uiout->text ("\n");
c906108c 851 }
6ba8e26f 852}
c906108c
SS
853
854
c906108c 855static void
0b39b52e 856tui_refresh_all_command (const char *arg, int from_tty)
c906108c 857{
1854bb21
SC
858 /* Make sure the curses mode is enabled. */
859 tui_enable ();
860
a21fcd8f 861 tui_refresh_all_win ();
c906108c
SS
862}
863
7806cea7
TT
864/* The tab width that should be used by the TUI. */
865
866unsigned int tui_tab_width = DEFAULT_TAB_LEN;
867
868/* The tab width as set by the user. */
869
870static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
871
d83f1fe6
TT
872/* After the tab width is set, call this to update the relevant
873 windows. */
874
875static void
876update_tab_width ()
877{
1ce3e844 878 for (tui_win_info *win_info : all_tui_windows ())
7806cea7 879 {
2d83e710 880 if (win_info->is_visible ())
1ce3e844 881 win_info->update_tab_width ();
7806cea7
TT
882 }
883}
884
885/* Callback for "set tui tab-width". */
886
887static void
888tui_set_tab_width (const char *ignore,
889 int from_tty, struct cmd_list_element *c)
890{
891 if (internal_tab_width == 0)
892 {
893 internal_tab_width = tui_tab_width;
894 error (_("Tab width must not be 0"));
895 }
896
897 tui_tab_width = internal_tab_width;
898 update_tab_width ();
899}
900
901/* Callback for "show tui tab-width". */
902
903static void
904tui_show_tab_width (struct ui_file *file, int from_tty,
905 struct cmd_list_element *c, const char *value)
906{
907 fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value);
908
909}
c906108c 910
c54da50d 911/* Set the tab width of the specified window. */
c906108c 912static void
0b39b52e 913tui_set_tab_width_command (const char *arg, int from_tty)
c906108c 914{
1854bb21
SC
915 /* Make sure the curses mode is enabled. */
916 tui_enable ();
63a33118 917 if (arg != NULL)
c906108c
SS
918 {
919 int ts;
920
921 ts = atoi (arg);
7806cea7
TT
922 if (ts <= 0)
923 warning (_("Tab widths greater than 0 must be specified."));
924 else
cb86fcc1 925 {
7806cea7
TT
926 internal_tab_width = ts;
927 tui_tab_width = ts;
928
929 update_tab_width ();
cb86fcc1 930 }
c906108c 931 }
6ba8e26f 932}
c906108c
SS
933
934
1cc6d956 935/* Set the height of the specified window. */
c906108c 936static void
4dde7b34 937tui_set_win_height_command (const char *arg, int from_tty)
c906108c 938{
1854bb21
SC
939 /* Make sure the curses mode is enabled. */
940 tui_enable ();
63a33118 941 if (arg != NULL)
c906108c 942 {
f71c8822
TT
943 std::string copy = arg;
944 char *buf = &copy[0];
6ba8e26f 945 char *buf_ptr = buf;
e65b5245 946 char *wname = NULL;
6ba8e26f 947 int new_height, i;
5b6fe301 948 struct tui_win_info *win_info;
c906108c 949
6ba8e26f
AC
950 wname = buf_ptr;
951 buf_ptr = strchr (buf_ptr, ' ');
63a33118 952 if (buf_ptr != NULL)
c906108c 953 {
6ba8e26f 954 *buf_ptr = (char) 0;
c906108c 955
ef5eab5a 956 /* Validate the window name. */
c906108c 957 for (i = 0; i < strlen (wname); i++)
6dce28e4 958 wname[i] = tolower (wname[i]);
6d012f14 959 win_info = tui_partial_win_by_name (wname);
c906108c 960
2d83e710 961 if (win_info == NULL || !win_info->is_visible ())
8a3fe4f8
AC
962 warning (_("Invalid window specified. \n\
963The window name specified must be valid and visible.\n"));
c906108c
SS
964 else
965 {
1cc6d956 966 /* Process the size. */
6ba8e26f 967 while (*(++buf_ptr) == ' ')
c906108c
SS
968 ;
969
6ba8e26f 970 if (*buf_ptr != (char) 0)
c906108c
SS
971 {
972 int negate = FALSE;
6ba8e26f
AC
973 int fixed_size = TRUE;
974 int input_no;;
c906108c 975
6ba8e26f 976 if (*buf_ptr == '+' || *buf_ptr == '-')
c906108c 977 {
6ba8e26f 978 if (*buf_ptr == '-')
c906108c 979 negate = TRUE;
6ba8e26f
AC
980 fixed_size = FALSE;
981 buf_ptr++;
c906108c 982 }
6ba8e26f
AC
983 input_no = atoi (buf_ptr);
984 if (input_no > 0)
c906108c
SS
985 {
986 if (negate)
6ba8e26f
AC
987 input_no *= (-1);
988 if (fixed_size)
989 new_height = input_no;
c906108c 990 else
cb2ce893 991 new_height = win_info->height + input_no;
ef5eab5a
MS
992
993 /* Now change the window's height, and adjust
994 all other windows around it. */
6ba8e26f
AC
995 if (tui_adjust_win_heights (win_info,
996 new_height) == TUI_FAILURE)
8a3fe4f8 997 warning (_("Invalid window height specified.\n%s"),
c906108c
SS
998 WIN_HEIGHT_USAGE);
999 else
3e752b04 1000 tui_update_gdb_sizes ();
c906108c
SS
1001 }
1002 else
8a3fe4f8 1003 warning (_("Invalid window height specified.\n%s"),
c906108c
SS
1004 WIN_HEIGHT_USAGE);
1005 }
1006 }
1007 }
1008 else
1009 printf_filtered (WIN_HEIGHT_USAGE);
c906108c
SS
1010 }
1011 else
1012 printf_filtered (WIN_HEIGHT_USAGE);
6ba8e26f 1013}
c906108c 1014
6ba8e26f 1015/* Function to adjust all window heights around the primary. */
22940a24 1016static enum tui_status
08ef48c5
MS
1017tui_adjust_win_heights (struct tui_win_info *primary_win_info,
1018 int new_height)
c906108c 1019{
22940a24 1020 enum tui_status status = TUI_FAILURE;
c906108c 1021
6ba8e26f 1022 if (new_height_ok (primary_win_info, new_height))
c906108c
SS
1023 {
1024 status = TUI_SUCCESS;
cb2ce893 1025 if (new_height != primary_win_info->height)
c906108c 1026 {
bc712bbf 1027 int diff;
5b6fe301 1028 struct tui_win_info *win_info;
3add462f 1029 struct tui_locator_window *locator = tui_locator_win_info_ptr ();
6ba8e26f 1030 enum tui_layout_type cur_layout = tui_current_layout ();
3df505f6 1031 int width = tui_term_width ();
c906108c 1032
cb2ce893 1033 diff = (new_height - primary_win_info->height) * (-1);
e5908723
MS
1034 if (cur_layout == SRC_COMMAND
1035 || cur_layout == DISASSEM_COMMAND)
c906108c 1036 {
5b6fe301 1037 struct tui_win_info *src_win_info;
c906108c 1038
3df505f6
TT
1039 primary_win_info->resize (new_height, width,
1040 0, primary_win_info->origin.y);
cb2ce893 1041 if (primary_win_info->type == CMD_WIN)
c906108c 1042 {
3891b65e 1043 win_info = *(tui_source_windows ().begin ());
6ba8e26f 1044 src_win_info = win_info;
c906108c
SS
1045 }
1046 else
1047 {
6d012f14 1048 win_info = tui_win_list[CMD_WIN];
6ba8e26f 1049 src_win_info = primary_win_info;
c906108c 1050 }
3df505f6
TT
1051 win_info->resize (win_info->height + diff, width,
1052 0, win_info->origin.y);
cb2ce893 1053 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
7908abbf 1054 if ((src_win_info->type == SRC_WIN
53e7cdba
TT
1055 || src_win_info->type == DISASSEM_WIN))
1056 {
1057 tui_source_window_base *src_base
1058 = (tui_source_window_base *) src_win_info;
1059 if (src_base->content.empty ())
e25d2004 1060 src_base->erase_source_content ();
53e7cdba 1061 }
c906108c
SS
1062 }
1063 else
1064 {
6ba8e26f 1065 struct tui_win_info *first_win;
7908abbf
TT
1066 struct tui_source_window_base *second_win;
1067 tui_source_window_base *src1;
c906108c 1068
6ba8e26f 1069 if (cur_layout == SRC_DISASSEM_COMMAND)
c906108c 1070 {
7908abbf
TT
1071 src1 = TUI_SRC_WIN;
1072 first_win = src1;
6ba8e26f 1073 second_win = TUI_DISASM_WIN;
c906108c
SS
1074 }
1075 else
1076 {
7908abbf 1077 src1 = nullptr;
6ba8e26f 1078 first_win = TUI_DATA_WIN;
3891b65e 1079 second_win = *(tui_source_windows ().begin ());
c906108c 1080 }
6ba8e26f 1081 if (primary_win_info == TUI_CMD_WIN)
ef5eab5a
MS
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;
6ba8e26f 1086 int second_split_diff = first_split_diff;
c906108c
SS
1087
1088 if (diff % 2)
1089 {
cb2ce893
TT
1090 if (first_win->height >
1091 second_win->height)
c906108c 1092 if (diff < 0)
6ba8e26f 1093 first_split_diff--;
c906108c 1094 else
6ba8e26f 1095 first_split_diff++;
c906108c
SS
1096 else
1097 {
1098 if (diff < 0)
6ba8e26f 1099 second_split_diff--;
c906108c 1100 else
6ba8e26f 1101 second_split_diff++;
c906108c
SS
1102 }
1103 }
1cc6d956
MS
1104 /* Make sure that the minimum hieghts are
1105 honored. */
cb2ce893 1106 while ((first_win->height + first_split_diff) < 3)
c906108c 1107 {
6ba8e26f
AC
1108 first_split_diff++;
1109 second_split_diff--;
c906108c 1110 }
cb2ce893 1111 while ((second_win->height + second_split_diff) < 3)
c906108c 1112 {
6ba8e26f
AC
1113 second_split_diff++;
1114 first_split_diff--;
c906108c 1115 }
3df505f6
TT
1116 first_win->resize (first_win->height + first_split_diff,
1117 width,
1118 0, first_win->origin.y);
1119 second_win->resize (second_win->height + second_split_diff,
1120 width,
1121 0, first_win->height - 1);
1122 locator->resize (2 /* 1 */, width,
1123 0, (second_win->origin.y
1124 + second_win->height + 1));
1125
1126 TUI_CMD_WIN->resize (new_height, width,
1127 0, locator->origin.y + 1);
c906108c
SS
1128 }
1129 else
1130 {
cb2ce893 1131 if ((TUI_CMD_WIN->height + diff) < 1)
ef5eab5a
MS
1132 { /* If there is no way to increase the command
1133 window take real estate from the 1st or 2nd
1134 window. */
cb2ce893 1135 if ((TUI_CMD_WIN->height + diff) < 1)
c906108c
SS
1136 {
1137 int i;
1c5313c5 1138
cb2ce893 1139 for (i = TUI_CMD_WIN->height + diff;
c906108c 1140 (i < 1); i++)
6ba8e26f 1141 if (primary_win_info == first_win)
cb2ce893 1142 second_win->height--;
c906108c 1143 else
cb2ce893 1144 first_win->height--;
c906108c
SS
1145 }
1146 }
6ba8e26f 1147 if (primary_win_info == first_win)
3df505f6 1148 first_win->resize (new_height, width, 0, 0);
c906108c 1149 else
3df505f6 1150 first_win->resize (first_win->height, width, 0, 0);
cb2ce893 1151 second_win->origin.y = first_win->height - 1;
6ba8e26f 1152 if (primary_win_info == second_win)
3df505f6
TT
1153 second_win->resize (new_height, width,
1154 0, first_win->height - 1);
c906108c 1155 else
3df505f6
TT
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));
cb2ce893
TT
1161 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
1162 if ((TUI_CMD_WIN->height + diff) < 1)
3df505f6 1163 TUI_CMD_WIN->resize (1, width, 0, locator->origin.y + 1);
c906108c 1164 else
3df505f6
TT
1165 TUI_CMD_WIN->resize (TUI_CMD_WIN->height + diff, width,
1166 0, locator->origin.y + 1);
c906108c 1167 }
53e7cdba 1168 if (src1 != nullptr && src1->content.empty ())
e25d2004 1169 src1->erase_source_content ();
53e7cdba 1170 if (second_win->content.empty ())
e25d2004 1171 second_win->erase_source_content ();
c906108c
SS
1172 }
1173 }
1174 }
1175
1176 return status;
6ba8e26f 1177}
c906108c 1178
5fcee43a 1179/* See tui-data.h. */
c906108c 1180
8903bd8a
TT
1181int
1182tui_win_info::max_height () const
1183{
1184 return tui_term_height () - 2;
1185}
1186
c906108c 1187static int
08ef48c5
MS
1188new_height_ok (struct tui_win_info *primary_win_info,
1189 int new_height)
c906108c 1190{
6ba8e26f 1191 int ok = (new_height < tui_term_height ());
c906108c
SS
1192
1193 if (ok)
1194 {
bc712bbf 1195 int diff;
6d012f14 1196 enum tui_layout_type cur_layout = tui_current_layout ();
c906108c 1197
cb2ce893 1198 diff = (new_height - primary_win_info->height) * (-1);
6d012f14 1199 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
c906108c 1200 {
8903bd8a
TT
1201 ok = (new_height <= primary_win_info->max_height ()
1202 && new_height >= MIN_CMD_WIN_HEIGHT);
c906108c 1203 if (ok)
1cc6d956 1204 { /* Check the total height. */
5b6fe301 1205 struct tui_win_info *win_info;
c906108c 1206
6ba8e26f 1207 if (primary_win_info == TUI_CMD_WIN)
3891b65e 1208 win_info = *(tui_source_windows ().begin ());
c906108c 1209 else
6d012f14 1210 win_info = TUI_CMD_WIN;
6ba8e26f 1211 ok = ((new_height +
cb2ce893 1212 (win_info->height + diff)) <= tui_term_height ());
c906108c
SS
1213 }
1214 }
1215 else
1216 {
6ba8e26f
AC
1217 int cur_total_height, total_height, min_height = 0;
1218 struct tui_win_info *first_win;
1219 struct tui_win_info *second_win;
c906108c 1220
6d012f14 1221 if (cur_layout == SRC_DISASSEM_COMMAND)
c906108c 1222 {
6ba8e26f
AC
1223 first_win = TUI_SRC_WIN;
1224 second_win = TUI_DISASM_WIN;
c906108c
SS
1225 }
1226 else
1227 {
6ba8e26f 1228 first_win = TUI_DATA_WIN;
3891b65e 1229 second_win = *(tui_source_windows ().begin ());
c906108c 1230 }
ef5eab5a
MS
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. */
6ba8e26f 1235 total_height = cur_total_height =
cb2ce893
TT
1236 (first_win->height + second_win->height - 1)
1237 + TUI_CMD_WIN->height + 1; /* Locator. */
6ba8e26f 1238 if (primary_win_info == TUI_CMD_WIN)
c906108c 1239 {
1cc6d956 1240 /* Locator included since first & second win share a line. */
cb2ce893
TT
1241 ok = ((first_win->height +
1242 second_win->height + diff) >=
e5908723
MS
1243 (MIN_WIN_HEIGHT * 2)
1244 && new_height >= MIN_CMD_WIN_HEIGHT);
c906108c
SS
1245 if (ok)
1246 {
e5908723 1247 total_height = new_height +
cb2ce893
TT
1248 (first_win->height +
1249 second_win->height + diff);
6ba8e26f 1250 min_height = MIN_CMD_WIN_HEIGHT;
c906108c
SS
1251 }
1252 }
1253 else
1254 {
6ba8e26f 1255 min_height = MIN_WIN_HEIGHT;
ef5eab5a
MS
1256
1257 /* First see if we can increase/decrease the command
1258 window. And make sure that the command window is at
1259 least 1 line. */
cb2ce893 1260 ok = ((TUI_CMD_WIN->height + diff) > 0);
c906108c 1261 if (!ok)
ef5eab5a
MS
1262 { /* Looks like we have to increase/decrease one of
1263 the other windows. */
6ba8e26f 1264 if (primary_win_info == first_win)
cb2ce893 1265 ok = (second_win->height + diff) >= min_height;
c906108c 1266 else
cb2ce893 1267 ok = (first_win->height + diff) >= min_height;
c906108c
SS
1268 }
1269 if (ok)
1270 {
6ba8e26f
AC
1271 if (primary_win_info == first_win)
1272 total_height = new_height +
cb2ce893
TT
1273 second_win->height +
1274 TUI_CMD_WIN->height + diff;
c906108c 1275 else
6ba8e26f 1276 total_height = new_height +
cb2ce893
TT
1277 first_win->height +
1278 TUI_CMD_WIN->height + diff;
c906108c
SS
1279 }
1280 }
ef5eab5a
MS
1281 /* Now make sure that the proposed total height doesn't
1282 exceed the old total height. */
c906108c 1283 if (ok)
e5908723
MS
1284 ok = (new_height >= min_height
1285 && total_height <= cur_total_height);
c906108c
SS
1286 }
1287 }
1288
1289 return ok;
6ba8e26f 1290}
c906108c
SS
1291
1292
c906108c 1293static void
0b39b52e 1294parse_scrolling_args (const char *arg,
08ef48c5 1295 struct tui_win_info **win_to_scroll,
6ba8e26f 1296 int *num_to_scroll)
c906108c 1297{
6ba8e26f
AC
1298 if (num_to_scroll)
1299 *num_to_scroll = 0;
1300 *win_to_scroll = tui_win_with_focus ();
c906108c 1301
ef5eab5a
MS
1302 /* First set up the default window to scroll, in case there is no
1303 window name arg. */
63a33118 1304 if (arg != NULL)
c906108c 1305 {
f71c8822 1306 char *buf_ptr;
c906108c 1307
1cc6d956 1308 /* Process the number of lines to scroll. */
f71c8822
TT
1309 std::string copy = arg;
1310 buf_ptr = &copy[0];
6ba8e26f 1311 if (isdigit (*buf_ptr))
c906108c 1312 {
6ba8e26f 1313 char *num_str;
c906108c 1314
6ba8e26f
AC
1315 num_str = buf_ptr;
1316 buf_ptr = strchr (buf_ptr, ' ');
63a33118 1317 if (buf_ptr != NULL)
c906108c 1318 {
6ba8e26f
AC
1319 *buf_ptr = (char) 0;
1320 if (num_to_scroll)
1321 *num_to_scroll = atoi (num_str);
1322 buf_ptr++;
c906108c 1323 }
6ba8e26f
AC
1324 else if (num_to_scroll)
1325 *num_to_scroll = atoi (num_str);
c906108c
SS
1326 }
1327
1cc6d956 1328 /* Process the window name if one is specified. */
63a33118 1329 if (buf_ptr != NULL)
c906108c 1330 {
a121b7c1 1331 const char *wname;
c906108c 1332
6ba8e26f
AC
1333 if (*buf_ptr == ' ')
1334 while (*(++buf_ptr) == ' ')
c906108c
SS
1335 ;
1336
6ba8e26f 1337 if (*buf_ptr != (char) 0)
c709a7c2 1338 {
c709a7c2 1339 /* Validate the window name. */
a121b7c1
PA
1340 for (char *p = buf_ptr; *p != '\0'; p++)
1341 *p = tolower (*p);
1342
1343 wname = buf_ptr;
c709a7c2 1344 }
a4b99e53
SC
1345 else
1346 wname = "?";
1347
6ba8e26f 1348 *win_to_scroll = tui_partial_win_by_name (wname);
c906108c 1349
ca5af91e
TT
1350 if (*win_to_scroll == NULL)
1351 error (_("Unrecognized window `%s'"), wname);
2d83e710 1352 if (!(*win_to_scroll)->is_visible ())
ca5af91e 1353 error (_("Window is not visible"));
6ba8e26f 1354 else if (*win_to_scroll == TUI_CMD_WIN)
3891b65e 1355 *win_to_scroll = *(tui_source_windows ().begin ());
c906108c 1356 }
c906108c 1357 }
6ba8e26f 1358}
7806cea7
TT
1359
1360/* Function to initialize gdb commands, for tui window
1361 manipulation. */
1362
1363void
1364_initialize_tui_win (void)
1365{
1366 static struct cmd_list_element *tui_setlist;
1367 static struct cmd_list_element *tui_showlist;
1368 struct cmd_list_element *cmd;
1369
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,
590042fc 1373 _("TUI configuration variables."),
7806cea7
TT
1374 &tui_setlist, "set tui ",
1375 0 /* allow-unknown */, &setlist);
1376 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
590042fc 1377 _("TUI configuration variables."),
7806cea7
TT
1378 &tui_showlist, "show tui ",
1379 0 /* allow-unknown */, &showlist);
1380
1381 add_com ("refresh", class_tui, tui_refresh_all_command,
89549d7f 1382 _("Refresh the terminal display."));
7806cea7
TT
1383
1384 cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1385Set the width (in characters) of tab stops.\n\
89549d7f 1386Usage: tabset N"));
7806cea7
TT
1387 deprecate_cmd (cmd, "set tui tab-width");
1388
1389 cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
1390Set or modify the height of a specified window.\n"
1391WIN_HEIGHT_USAGE
1392"Window names are:\n\
89549d7f
TT
1393 src : the source window\n\
1394 cmd : the command window\n\
1395 asm : the disassembly window\n\
1396 regs : the register display"));
7806cea7
TT
1397 add_com_alias ("wh", "winheight", class_tui, 0);
1398 set_cmd_completer (cmd, winheight_completer);
1399 add_info ("win", tui_all_windows_info,
89549d7f 1400 _("List of all displayed windows."));
7806cea7
TT
1401 cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
1402Set focus to named window or next/prev window.\n"
1403FOCUS_USAGE
1404"Valid Window names are:\n\
89549d7f
TT
1405 src : the source window\n\
1406 asm : the disassembly window\n\
1407 regs : the register display\n\
1408 cmd : the command window"));
7806cea7
TT
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, _("\
1412Scroll window forward.\n\
89549d7f 1413Usage: + [WIN] [N]"));
7806cea7
TT
1414 add_com ("-", class_tui, tui_scroll_backward_command, _("\
1415Scroll window backward.\n\
89549d7f 1416Usage: - [WIN] [N]"));
7806cea7
TT
1417 add_com ("<", class_tui, tui_scroll_left_command, _("\
1418Scroll window text to the left.\n\
89549d7f 1419Usage: < [WIN] [N]"));
7806cea7
TT
1420 add_com (">", class_tui, tui_scroll_right_command, _("\
1421Scroll window text to the right.\n\
89549d7f 1422Usage: > [WIN] [N]"));
7806cea7
TT
1423
1424 /* Define the tui control variables. */
1425 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1426 &tui_border_kind, _("\
1427Set the kind of border for TUI windows."), _("\
1428Show the kind of border for TUI windows."), _("\
1429This variable controls the border of TUI windows:\n\
89549d7f
TT
1430 space use a white space\n\
1431 ascii use ascii characters + - | for the border\n\
1432 acs use the Alternate Character Set"),
7806cea7
TT
1433 tui_set_var_cmd,
1434 show_tui_border_kind,
1435 &tui_setlist, &tui_showlist);
1436
1437 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1438 &tui_border_mode, _("\
1439Set the attribute mode to use for the TUI window borders."), _("\
1440Show the attribute mode to use for the TUI window borders."), _("\
1441This variable controls the attributes to use for the window borders:\n\
89549d7f
TT
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"),
7806cea7
TT
1449 tui_set_var_cmd,
1450 show_tui_border_mode,
1451 &tui_setlist, &tui_showlist);
1452
1453 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1454 &tui_active_border_mode, _("\
1455Set the attribute mode to use for the active TUI window border."), _("\
1456Show the attribute mode to use for the active TUI window border."), _("\
1457This variable controls the attributes to use for the active window border:\n\
89549d7f
TT
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"),
7806cea7
TT
1465 tui_set_var_cmd,
1466 show_tui_active_border_mode,
1467 &tui_setlist, &tui_showlist);
1468
1469 add_setshow_zuinteger_cmd ("tab-width", no_class,
1470 &internal_tab_width, _("\
1471Set the tab width, in characters, for the TUI."), _("\
590042fc 1472Show the tab witdh, in characters, for the TUI."), _("\
7806cea7
TT
1473This 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);
1476}
This page took 2.289415 seconds and 4 git commands to generate.