Revert "2020-04-29 Sterling Augustine <saugustine@google.com>"
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
CommitLineData
f377b406 1/* TUI window generic functions.
f33c6cbf 2
b811d2c2 3 Copyright (C) 1998-2020 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"
a2a7af0c 33#include "cli/cli-style.h"
3e752b04 34#include "top.h"
52575520 35#include "source.h"
400b5eca 36#include "gdbsupport/event-loop.h"
45e42163 37#include "gdbcmd.h"
93b54c8e 38#include "async-event.h"
c906108c 39
d7b2e967 40#include "tui/tui.h"
c4ef48c6 41#include "tui/tui-io.h"
ce38393b 42#include "tui/tui-command.h"
d7b2e967 43#include "tui/tui-data.h"
3df505f6 44#include "tui/tui-layout.h"
d7b2e967
AC
45#include "tui/tui-wingeneral.h"
46#include "tui/tui-stack.h"
47#include "tui/tui-regs.h"
48#include "tui/tui-disasm.h"
49#include "tui/tui-source.h"
50#include "tui/tui-winsource.h"
2c0b251b 51#include "tui/tui-win.h"
c906108c 52
6a83354a 53#include "gdb_curses.h"
96ec9981 54#include <ctype.h>
dbda9972 55#include "readline/readline.h"
9f6ad286 56#include "gdbsupport/gdb_string_view.h"
96ec9981 57
9612b5ec
UW
58#include <signal.h>
59
0b39b52e
TT
60static void tui_set_tab_width_command (const char *, int);
61static void tui_refresh_all_command (const char *, int);
1d12d88f 62static void tui_all_windows_info (const char *, int);
0b39b52e
TT
63static void tui_scroll_forward_command (const char *, int);
64static void tui_scroll_backward_command (const char *, int);
65static void tui_scroll_left_command (const char *, int);
66static void tui_scroll_right_command (const char *, int);
67static void parse_scrolling_args (const char *,
08ef48c5
MS
68 struct tui_win_info **,
69 int *);
c906108c
SS
70
71
17aae570
SC
72#ifndef ACS_LRCORNER
73# define ACS_LRCORNER '+'
74#endif
75#ifndef ACS_LLCORNER
76# define ACS_LLCORNER '+'
77#endif
78#ifndef ACS_ULCORNER
79# define ACS_ULCORNER '+'
80#endif
81#ifndef ACS_URCORNER
82# define ACS_URCORNER '+'
83#endif
84#ifndef ACS_HLINE
85# define ACS_HLINE '-'
86#endif
87#ifndef ACS_VLINE
88# define ACS_VLINE '|'
89#endif
90
af101512 91/* Possible values for tui-border-kind variable. */
40478521 92static const char *const tui_border_kind_enums[] = {
af101512
SC
93 "space",
94 "ascii",
95 "acs",
96 NULL
97};
98
99/* Possible values for tui-border-mode and tui-active-border-mode. */
40478521 100static const char *const tui_border_mode_enums[] = {
af101512
SC
101 "normal",
102 "standout",
103 "reverse",
104 "half",
105 "half-standout",
106 "bold",
107 "bold-standout",
108 NULL
109};
110
111struct tui_translate
112{
113 const char *name;
114 int value;
115};
116
117/* Translation table for border-mode variables.
118 The list of values must be terminated by a NULL.
119 After the NULL value, an entry defines the default. */
3d34df0a 120static struct tui_translate tui_border_mode_translate[] = {
af101512
SC
121 { "normal", A_NORMAL },
122 { "standout", A_STANDOUT },
123 { "reverse", A_REVERSE },
124 { "half", A_DIM },
125 { "half-standout", A_DIM | A_STANDOUT },
126 { "bold", A_BOLD },
127 { "bold-standout", A_BOLD | A_STANDOUT },
128 { 0, 0 },
129 { "normal", A_NORMAL }
130};
131
132/* Translation tables for border-kind, one for each border
133 character (see wborder, border curses operations).
134 -1 is used to indicate the ACS because ACS characters
135 are determined at run time by curses (depends on terminal). */
3d34df0a 136static struct tui_translate tui_border_kind_translate_vline[] = {
af101512
SC
137 { "space", ' ' },
138 { "ascii", '|' },
139 { "acs", -1 },
140 { 0, 0 },
141 { "ascii", '|' }
142};
143
3d34df0a 144static struct tui_translate tui_border_kind_translate_hline[] = {
af101512
SC
145 { "space", ' ' },
146 { "ascii", '-' },
147 { "acs", -1 },
148 { 0, 0 },
149 { "ascii", '-' }
150};
151
3d34df0a 152static struct tui_translate tui_border_kind_translate_ulcorner[] = {
af101512
SC
153 { "space", ' ' },
154 { "ascii", '+' },
155 { "acs", -1 },
156 { 0, 0 },
157 { "ascii", '+' }
158};
159
3d34df0a 160static struct tui_translate tui_border_kind_translate_urcorner[] = {
af101512
SC
161 { "space", ' ' },
162 { "ascii", '+' },
163 { "acs", -1 },
164 { 0, 0 },
165 { "ascii", '+' }
166};
167
3d34df0a 168static struct tui_translate tui_border_kind_translate_llcorner[] = {
af101512
SC
169 { "space", ' ' },
170 { "ascii", '+' },
171 { "acs", -1 },
172 { 0, 0 },
173 { "ascii", '+' }
174};
175
3d34df0a 176static struct tui_translate tui_border_kind_translate_lrcorner[] = {
af101512
SC
177 { "space", ' ' },
178 { "ascii", '+' },
179 { "acs", -1 },
180 { 0, 0 },
181 { "ascii", '+' }
182};
183
184
185/* Tui configuration variables controlled with set/show command. */
3d34df0a 186static const char *tui_active_border_mode = "bold-standout";
920d2a44 187static void
08ef48c5
MS
188show_tui_active_border_mode (struct ui_file *file,
189 int from_tty,
190 struct cmd_list_element *c,
191 const char *value)
920d2a44
AC
192{
193 fprintf_filtered (file, _("\
194The attribute mode to use for the active TUI window border is \"%s\".\n"),
195 value);
196}
197
3d34df0a 198static const char *tui_border_mode = "normal";
920d2a44 199static void
08ef48c5
MS
200show_tui_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 TUI window borders is \"%s\".\n"),
207 value);
208}
209
3d34df0a 210static const char *tui_border_kind = "acs";
920d2a44 211static void
08ef48c5
MS
212show_tui_border_kind (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, _("The kind of border for TUI windows is \"%s\".\n"),
218 value);
219}
220
af101512 221
1cc6d956
MS
222/* Tui internal configuration variables. These variables are updated
223 by tui_update_variables to reflect the tui configuration
af101512
SC
224 variables. */
225chtype tui_border_vline;
226chtype tui_border_hline;
227chtype tui_border_ulcorner;
228chtype tui_border_urcorner;
229chtype tui_border_llcorner;
230chtype tui_border_lrcorner;
231
232int tui_border_attrs;
233int tui_active_border_attrs;
234
235/* Identify the item in the translation table.
236 When the item is not recognized, use the default entry. */
237static struct tui_translate *
238translate (const char *name, struct tui_translate *table)
239{
240 while (table->name)
241 {
242 if (name && strcmp (table->name, name) == 0)
243 return table;
244 table++;
245 }
246
247 /* Not found, return default entry. */
248 table++;
249 return table;
250}
251
252/* Update the tui internal configuration according to gdb settings.
253 Returns 1 if the configuration has changed and the screen should
254 be redrawn. */
87d557ae
TT
255bool
256tui_update_variables ()
af101512 257{
87d557ae 258 bool need_redraw = false;
af101512
SC
259 struct tui_translate *entry;
260
261 entry = translate (tui_border_mode, tui_border_mode_translate);
262 if (tui_border_attrs != entry->value)
263 {
264 tui_border_attrs = entry->value;
87d557ae 265 need_redraw = true;
af101512
SC
266 }
267 entry = translate (tui_active_border_mode, tui_border_mode_translate);
268 if (tui_active_border_attrs != entry->value)
269 {
270 tui_active_border_attrs = entry->value;
87d557ae 271 need_redraw = true;
af101512
SC
272 }
273
274 /* If one corner changes, all characters are changed.
275 Only check the first one. The ACS characters are determined at
276 run time by curses terminal management. */
277 entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner);
278 if (tui_border_lrcorner != (chtype) entry->value)
279 {
280 tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value;
87d557ae 281 need_redraw = true;
af101512
SC
282 }
283 entry = translate (tui_border_kind, tui_border_kind_translate_llcorner);
284 tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value;
285
286 entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner);
287 tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value;
288
289 entry = translate (tui_border_kind, tui_border_kind_translate_urcorner);
290 tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value;
291
292 entry = translate (tui_border_kind, tui_border_kind_translate_hline);
293 tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value;
294
295 entry = translate (tui_border_kind, tui_border_kind_translate_vline);
296 tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value;
297
298 return need_redraw;
299}
300
c9684879 301static void
981a3fb3 302set_tui_cmd (const char *args, int from_tty)
c9684879
SC
303{
304}
305
306static void
981a3fb3 307show_tui_cmd (const char *args, int from_tty)
c9684879
SC
308{
309}
af101512 310
10f59415
SC
311static struct cmd_list_element *tuilist;
312
10f59415 313struct cmd_list_element **
da745b36 314tui_get_cmd_list (void)
10f59415
SC
315{
316 if (tuilist == 0)
0743fc83
TT
317 add_basic_prefix_cmd ("tui", class_tui,
318 _("Text User Interface commands."),
319 &tuilist, "tui ", 0, &cmdlist);
10f59415
SC
320 return &tuilist;
321}
322
6cdb25f4
EZ
323/* The set_func hook of "set tui ..." commands that affect the window
324 borders on the TUI display. */
3b5c1d49
SM
325
326static void
eb4c3f4a
TT
327tui_set_var_cmd (const char *null_args,
328 int from_tty, struct cmd_list_element *c)
6cdb25f4
EZ
329{
330 if (tui_update_variables () && tui_active)
331 tui_rehighlight_all ();
332}
333
45e42163
TT
334\f
335
336/* True if TUI resizes should print a message. This is used by the
337 test suite. */
338
339static bool resize_message;
340
341static void
342show_tui_resize_message (struct ui_file *file, int from_tty,
343 struct cmd_list_element *c, const char *value)
344{
345 fprintf_filtered (file, _("TUI resize messaging is %s.\n"), value);
346}
347
348\f
349
97605e61
AB
350/* Generic window name completion function. Complete window name pointed
351 to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
352 window names 'next' and 'prev' will also be considered as possible
353 completions of the window name. */
2e52ae68 354
eb3ff9a5
PA
355static void
356window_name_completer (completion_tracker &tracker,
357 int include_next_prev_p,
97605e61 358 const char *text, const char *word)
2e52ae68 359{
625ad440 360 std::vector<const char *> completion_name_vec;
2e52ae68 361
1ce3e844 362 for (tui_win_info *win_info : all_tui_windows ())
2e52ae68
PP
363 {
364 const char *completion_name = NULL;
365
366 /* We can't focus on an invisible window. */
2d83e710 367 if (!win_info->is_visible ())
2e52ae68
PP
368 continue;
369
1ce3e844 370 completion_name = win_info->name ();
150375dc 371 gdb_assert (completion_name != NULL);
625ad440 372 completion_name_vec.push_back (completion_name);
2e52ae68
PP
373 }
374
375 /* If no windows are considered visible then the TUI has not yet been
376 initialized. But still "focus src" and "focus cmd" will work because
377 invoking the focus command will entail initializing the TUI which sets the
416eb92d 378 default layout to "src". */
625ad440 379 if (completion_name_vec.empty ())
2e52ae68 380 {
625ad440
SM
381 completion_name_vec.push_back (SRC_NAME);
382 completion_name_vec.push_back (CMD_NAME);
2e52ae68
PP
383 }
384
97605e61
AB
385 if (include_next_prev_p)
386 {
625ad440
SM
387 completion_name_vec.push_back ("next");
388 completion_name_vec.push_back ("prev");
97605e61 389 }
2e52ae68 390
2e52ae68 391
625ad440
SM
392 completion_name_vec.push_back (NULL);
393 complete_on_enum (tracker, completion_name_vec.data (), text, word);
2e52ae68
PP
394}
395
97605e61
AB
396/* Complete possible window names to focus on. TEXT is the complete text
397 entered so far, WORD is the word currently being completed. */
398
eb3ff9a5 399static void
97605e61 400focus_completer (struct cmd_list_element *ignore,
eb3ff9a5
PA
401 completion_tracker &tracker,
402 const char *text, const char *word)
97605e61 403{
eb3ff9a5 404 window_name_completer (tracker, 1, text, word);
97605e61
AB
405}
406
407/* Complete possible window names for winheight command. TEXT is the
408 complete text entered so far, WORD is the word currently being
409 completed. */
410
eb3ff9a5 411static void
97605e61 412winheight_completer (struct cmd_list_element *ignore,
eb3ff9a5 413 completion_tracker &tracker,
97605e61
AB
414 const char *text, const char *word)
415{
416 /* The first word is the window name. That we can complete. Subsequent
417 words can't be completed. */
418 if (word != text)
eb3ff9a5 419 return;
97605e61 420
eb3ff9a5 421 window_name_completer (tracker, 0, text, word);
97605e61
AB
422}
423
3e752b04
SC
424/* Update gdb's knowledge of the terminal size. */
425void
d02c80cd 426tui_update_gdb_sizes (void)
3e752b04 427{
d6e5e7f7
PP
428 int width, height;
429
430 if (tui_active)
431 {
cb2ce893
TT
432 width = TUI_CMD_WIN->width;
433 height = TUI_CMD_WIN->height;
d6e5e7f7
PP
434 }
435 else
436 {
437 width = tui_term_width ();
438 height = tui_term_height ();
439 }
440
441 set_screen_width_and_height (width, height);
3e752b04
SC
442}
443
c906108c 444
c906108c 445void
13446e05 446tui_win_info::forward_scroll (int num_to_scroll)
c906108c 447{
13446e05 448 if (num_to_scroll == 0)
cb2ce893 449 num_to_scroll = height - 3;
c906108c 450
c3bd716f 451 do_scroll_vertical (num_to_scroll);
a21fcd8f 452}
c906108c 453
c906108c 454void
13446e05 455tui_win_info::backward_scroll (int num_to_scroll)
c906108c 456{
13446e05 457 if (num_to_scroll == 0)
cb2ce893 458 num_to_scroll = height - 3;
13446e05 459
c3bd716f 460 do_scroll_vertical (-num_to_scroll);
a21fcd8f 461}
c906108c
SS
462
463
c906108c 464void
13446e05 465tui_win_info::left_scroll (int num_to_scroll)
c906108c 466{
13446e05
TT
467 if (num_to_scroll == 0)
468 num_to_scroll = 1;
469
c3bd716f 470 do_scroll_horizontal (num_to_scroll);
a21fcd8f 471}
c906108c
SS
472
473
c906108c 474void
13446e05 475tui_win_info::right_scroll (int num_to_scroll)
c906108c 476{
13446e05
TT
477 if (num_to_scroll == 0)
478 num_to_scroll = 1;
479
c3bd716f 480 do_scroll_horizontal (-num_to_scroll);
e8b915dc 481}
c906108c
SS
482
483
c906108c 484void
a21fcd8f 485tui_refresh_all_win (void)
c906108c 486{
3e266828 487 clearok (curscr, TRUE);
1ce3e844 488 tui_refresh_all ();
bc712bbf 489}
c906108c 490
6cdb25f4
EZ
491void
492tui_rehighlight_all (void)
493{
1ce3e844 494 for (tui_win_info *win_info : all_tui_windows ())
b4ef5aeb 495 win_info->check_and_display_highlight_if_needed ();
6cdb25f4 496}
c906108c 497
b021a221 498/* Resize all the windows based on the terminal size. This function
ae2b5380 499 gets called from within the readline SIGWINCH handler. */
c906108c 500void
6ba8e26f 501tui_resize_all (void)
c906108c 502{
6ba8e26f 503 int height_diff, width_diff;
9255ee31 504 int screenheight, screenwidth;
c906108c 505
9255ee31 506 rl_get_screen_size (&screenheight, &screenwidth);
6ba8e26f
AC
507 width_diff = screenwidth - tui_term_width ();
508 height_diff = screenheight - tui_term_height ();
509 if (height_diff || width_diff)
c906108c 510 {
5b6fe301 511 struct tui_win_info *win_with_focus = tui_win_with_focus ();
c906108c 512
10f59415
SC
513#ifdef HAVE_RESIZE_TERM
514 resize_term (screenheight, screenwidth);
515#endif
1cc6d956 516 /* Turn keypad off while we resize. */
6ba8e26f 517 if (win_with_focus != TUI_CMD_WIN)
7523da63 518 keypad (TUI_CMD_WIN->handle.get (), FALSE);
3e752b04 519 tui_update_gdb_sizes ();
dd1abb8c
AC
520 tui_set_term_height_to (screenheight);
521 tui_set_term_width_to (screenwidth);
3d979945 522
c366c1f0
TT
523 /* erase + clearok are used instead of a straightforward clear as
524 AIX 5.3 does not define clear. */
525 erase ();
526 clearok (curscr, TRUE);
3d979945 527 tui_apply_current_layout ();
1cc6d956
MS
528 /* Turn keypad back on, unless focus is in the command
529 window. */
6ba8e26f 530 if (win_with_focus != TUI_CMD_WIN)
7523da63 531 keypad (TUI_CMD_WIN->handle.get (), TRUE);
c906108c 532 }
6ba8e26f 533}
c906108c 534
2c0b251b 535#ifdef SIGWINCH
c4ef48c6
PP
536/* Token for use by TUI's asynchronous SIGWINCH handler. */
537static struct async_signal_handler *tui_sigwinch_token;
538
539/* TUI's SIGWINCH signal handler. */
2c0b251b 540static void
6ba8e26f 541tui_sigwinch_handler (int signal)
c906108c 542{
c4ef48c6 543 mark_async_signal_handler (tui_sigwinch_token);
9abd8a65 544 tui_set_win_resized_to (true);
6ba8e26f 545}
c4ef48c6
PP
546
547/* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
548static void
549tui_async_resize_screen (gdb_client_data arg)
550{
a88d0bb3
PP
551 rl_resize_terminal ();
552
c4ef48c6 553 if (!tui_active)
a88d0bb3
PP
554 {
555 int screen_height, screen_width;
c4ef48c6 556
a88d0bb3
PP
557 rl_get_screen_size (&screen_height, &screen_width);
558 set_screen_width_and_height (screen_width, screen_height);
559
560 /* win_resized is left set so that the next call to tui_enable()
561 resizes the TUI windows. */
562 }
563 else
564 {
9abd8a65 565 tui_set_win_resized_to (false);
a88d0bb3
PP
566 tui_resize_all ();
567 tui_refresh_all_win ();
568 tui_update_gdb_sizes ();
45e42163
TT
569 if (resize_message)
570 {
571 static int count;
572 printf_unfiltered ("@@ resize done %d, size = %dx%d\n", count,
573 tui_term_width (), tui_term_height ());
574 ++count;
575 }
a88d0bb3
PP
576 tui_redisplay_readline ();
577 }
c4ef48c6 578}
2c0b251b 579#endif
c906108c 580
c4ef48c6
PP
581/* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
582 uninstalled when we exit TUI, so the handler should not assume that TUI is
583 always active. */
9612b5ec
UW
584void
585tui_initialize_win (void)
586{
587#ifdef SIGWINCH
c4ef48c6
PP
588 tui_sigwinch_token
589 = create_async_signal_handler (tui_async_resize_screen, NULL);
590
591 {
9612b5ec 592#ifdef HAVE_SIGACTION
c4ef48c6 593 struct sigaction old_winch;
1c5313c5 594
c4ef48c6
PP
595 memset (&old_winch, 0, sizeof (old_winch));
596 old_winch.sa_handler = &tui_sigwinch_handler;
a344fc09 597#ifdef SA_RESTART
c4ef48c6 598 old_winch.sa_flags = SA_RESTART;
a344fc09 599#endif
c4ef48c6 600 sigaction (SIGWINCH, &old_winch, NULL);
9612b5ec 601#else
c4ef48c6 602 signal (SIGWINCH, &tui_sigwinch_handler);
9612b5ec 603#endif
c4ef48c6 604 }
9612b5ec
UW
605#endif
606}
c906108c
SS
607
608
c906108c 609static void
0b39b52e 610tui_scroll_forward_command (const char *arg, int from_tty)
c906108c 611{
6ba8e26f 612 int num_to_scroll = 1;
5b6fe301 613 struct tui_win_info *win_to_scroll;
c906108c 614
1854bb21
SC
615 /* Make sure the curses mode is enabled. */
616 tui_enable ();
63a33118 617 if (arg == NULL)
cafb3438 618 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 619 else
6ba8e26f 620 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 621 win_to_scroll->forward_scroll (num_to_scroll);
e8b915dc 622}
c906108c
SS
623
624
c906108c 625static void
0b39b52e 626tui_scroll_backward_command (const char *arg, int from_tty)
c906108c 627{
6ba8e26f 628 int num_to_scroll = 1;
5b6fe301 629 struct tui_win_info *win_to_scroll;
c906108c 630
1854bb21
SC
631 /* Make sure the curses mode is enabled. */
632 tui_enable ();
63a33118 633 if (arg == NULL)
cafb3438 634 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 635 else
6ba8e26f 636 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 637 win_to_scroll->backward_scroll (num_to_scroll);
e8b915dc 638}
c906108c
SS
639
640
c906108c 641static void
0b39b52e 642tui_scroll_left_command (const char *arg, int from_tty)
c906108c 643{
6ba8e26f 644 int num_to_scroll;
5b6fe301 645 struct tui_win_info *win_to_scroll;
c906108c 646
1854bb21
SC
647 /* Make sure the curses mode is enabled. */
648 tui_enable ();
6ba8e26f 649 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 650 win_to_scroll->left_scroll (num_to_scroll);
e8b915dc 651}
c906108c
SS
652
653
c906108c 654static void
0b39b52e 655tui_scroll_right_command (const char *arg, int from_tty)
c906108c 656{
6ba8e26f 657 int num_to_scroll;
5b6fe301 658 struct tui_win_info *win_to_scroll;
c906108c 659
1854bb21
SC
660 /* Make sure the curses mode is enabled. */
661 tui_enable ();
6ba8e26f 662 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 663 win_to_scroll->right_scroll (num_to_scroll);
e8b915dc 664}
c906108c
SS
665
666
9f6ad286
TT
667/* Answer the window represented by name. */
668static struct tui_win_info *
669tui_partial_win_by_name (gdb::string_view name)
670{
e098d18c
TT
671 struct tui_win_info *best = nullptr;
672
9f6ad286
TT
673 if (name != NULL)
674 {
675 for (tui_win_info *item : all_tui_windows ())
676 {
677 const char *cur_name = item->name ();
678
e098d18c 679 if (name == cur_name)
9f6ad286 680 return item;
e098d18c
TT
681 if (startswith (cur_name, name))
682 {
683 if (best != nullptr)
684 error (_("Window name \"%*s\" is ambiguous"),
685 (int) name.size (), name.data ());
686 best = item;
687 }
9f6ad286
TT
688 }
689 }
690
e098d18c 691 return best;
9f6ad286
TT
692}
693
6ba8e26f 694/* Set focus to the window named by 'arg'. */
c906108c 695static void
01aeb396 696tui_set_focus_command (const char *arg, int from_tty)
c906108c 697{
01aeb396
TT
698 tui_enable ();
699
ca793b96
TT
700 if (arg == NULL)
701 error_no_arg (_("name of window to focus"));
c906108c 702
ca793b96 703 struct tui_win_info *win_info = NULL;
c906108c 704
ca793b96
TT
705 if (subset_compare (arg, "next"))
706 win_info = tui_next_win (tui_win_with_focus ());
707 else if (subset_compare (arg, "prev"))
708 win_info = tui_prev_win (tui_win_with_focus ());
c906108c 709 else
ca793b96
TT
710 win_info = tui_partial_win_by_name (arg);
711
712 if (win_info == NULL)
713 error (_("Unrecognized window name \"%s\""), arg);
714 if (!win_info->is_visible ())
715 error (_("Window \"%s\" is not visible"), arg);
716
717 tui_set_win_focus_to (win_info);
718 keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
719 printf_filtered (_("Focus set to %s window.\n"),
720 tui_win_with_focus ()->name ());
6ba8e26f 721}
c906108c 722
c906108c 723static void
1d12d88f 724tui_all_windows_info (const char *arg, int from_tty)
c906108c 725{
82e3b564
TT
726 if (!tui_active)
727 {
728 printf_filtered (_("The TUI is not active.\n"));
729 return;
730 }
731
5b6fe301 732 struct tui_win_info *win_with_focus = tui_win_with_focus ();
25a2915e
TT
733 struct ui_out *uiout = current_uiout;
734
735 ui_out_emit_table table_emitter (uiout, 3, -1, "tui-windows");
736 uiout->table_header (10, ui_left, "name", "Name");
737 uiout->table_header (5, ui_right, "lines", "Lines");
738 uiout->table_header (10, ui_left, "focus", "Focus");
739 uiout->table_body ();
c906108c 740
1ce3e844 741 for (tui_win_info *win_info : all_tui_windows ())
2d83e710 742 if (win_info->is_visible ())
c906108c 743 {
25a2915e
TT
744 ui_out_emit_tuple tuple_emitter (uiout, nullptr);
745
746 uiout->field_string ("name", win_info->name ());
747 uiout->field_signed ("lines", win_info->height);
1ce3e844 748 if (win_with_focus == win_info)
25a2915e 749 uiout->field_string ("focus", _("(has focus)"));
c906108c 750 else
25a2915e
TT
751 uiout->field_skip ("focus");
752 uiout->text ("\n");
c906108c 753 }
6ba8e26f 754}
c906108c
SS
755
756
c906108c 757static void
0b39b52e 758tui_refresh_all_command (const char *arg, int from_tty)
c906108c 759{
1854bb21
SC
760 /* Make sure the curses mode is enabled. */
761 tui_enable ();
762
a21fcd8f 763 tui_refresh_all_win ();
c906108c
SS
764}
765
7806cea7
TT
766/* The tab width that should be used by the TUI. */
767
768unsigned int tui_tab_width = DEFAULT_TAB_LEN;
769
770/* The tab width as set by the user. */
771
772static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
773
d83f1fe6
TT
774/* After the tab width is set, call this to update the relevant
775 windows. */
776
777static void
778update_tab_width ()
779{
1ce3e844 780 for (tui_win_info *win_info : all_tui_windows ())
7806cea7 781 {
2d83e710 782 if (win_info->is_visible ())
1ce3e844 783 win_info->update_tab_width ();
7806cea7
TT
784 }
785}
786
787/* Callback for "set tui tab-width". */
788
789static void
790tui_set_tab_width (const char *ignore,
791 int from_tty, struct cmd_list_element *c)
792{
793 if (internal_tab_width == 0)
794 {
795 internal_tab_width = tui_tab_width;
796 error (_("Tab width must not be 0"));
797 }
798
799 tui_tab_width = internal_tab_width;
800 update_tab_width ();
801}
802
803/* Callback for "show tui tab-width". */
804
805static void
806tui_show_tab_width (struct ui_file *file, int from_tty,
807 struct cmd_list_element *c, const char *value)
808{
809 fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value);
810
811}
c906108c 812
d1da6b01
TT
813/* See tui-win.h. */
814
815bool compact_source = false;
816
817/* Callback for "set tui compact-source". */
818
819static void
820tui_set_compact_source (const char *ignore, int from_tty,
821 struct cmd_list_element *c)
822{
823 if (TUI_SRC_WIN != nullptr)
824 TUI_SRC_WIN->refill ();
825}
826
827/* Callback for "show tui compact-source". */
828
829static void
830tui_show_compact_source (struct ui_file *file, int from_tty,
831 struct cmd_list_element *c, const char *value)
832{
833 printf_filtered (_("TUI source window compactness is %s.\n"), value);
834}
835
c54da50d 836/* Set the tab width of the specified window. */
c906108c 837static void
0b39b52e 838tui_set_tab_width_command (const char *arg, int from_tty)
c906108c 839{
1854bb21
SC
840 /* Make sure the curses mode is enabled. */
841 tui_enable ();
63a33118 842 if (arg != NULL)
c906108c
SS
843 {
844 int ts;
845
846 ts = atoi (arg);
7806cea7
TT
847 if (ts <= 0)
848 warning (_("Tab widths greater than 0 must be specified."));
849 else
cb86fcc1 850 {
7806cea7
TT
851 internal_tab_width = ts;
852 tui_tab_width = ts;
853
854 update_tab_width ();
cb86fcc1 855 }
c906108c 856 }
6ba8e26f 857}
c906108c
SS
858
859
1cc6d956 860/* Set the height of the specified window. */
c906108c 861static void
4dde7b34 862tui_set_win_height_command (const char *arg, int from_tty)
c906108c 863{
1854bb21
SC
864 /* Make sure the curses mode is enabled. */
865 tui_enable ();
ca793b96
TT
866 if (arg == NULL)
867 error_no_arg (_("name of window"));
c906108c 868
ca793b96
TT
869 const char *buf = arg;
870 const char *buf_ptr = buf;
871 int new_height;
872 struct tui_win_info *win_info;
c906108c 873
ca793b96 874 buf_ptr = skip_to_space (buf_ptr);
78e8cb91 875
ca793b96
TT
876 /* Validate the window name. */
877 gdb::string_view wname (buf, buf_ptr - buf);
878 win_info = tui_partial_win_by_name (wname);
78e8cb91 879
ca793b96
TT
880 if (win_info == NULL)
881 error (_("Unrecognized window name \"%s\""), arg);
882 if (!win_info->is_visible ())
883 error (_("Window \"%s\" is not visible"), arg);
884
885 /* Process the size. */
886 buf_ptr = skip_spaces (buf_ptr);
887
888 if (*buf_ptr != '\0')
889 {
890 bool negate = false;
891 bool fixed_size = true;
892 int input_no;;
893
894 if (*buf_ptr == '+' || *buf_ptr == '-')
895 {
896 if (*buf_ptr == '-')
897 negate = true;
898 fixed_size = false;
899 buf_ptr++;
900 }
901 input_no = atoi (buf_ptr);
902 if (input_no > 0)
903 {
904 if (negate)
905 input_no *= (-1);
906 if (fixed_size)
907 new_height = input_no;
908 else
909 new_height = win_info->height + input_no;
910
911 /* Now change the window's height, and adjust
912 all other windows around it. */
913 tui_adjust_window_height (win_info, new_height);
914 tui_update_gdb_sizes ();
c906108c
SS
915 }
916 else
ca793b96 917 error (_("Invalid window height specified"));
c906108c 918 }
6ba8e26f 919}
c906108c 920
5fcee43a 921/* See tui-data.h. */
c906108c 922
8903bd8a
TT
923int
924tui_win_info::max_height () const
925{
926 return tui_term_height () - 2;
927}
928
7c043ba6
TT
929/* See tui-data.h. */
930
931int
932tui_gen_win_info::max_width () const
933{
934 return tui_term_width () - 2;
935}
936
c906108c 937static void
0b39b52e 938parse_scrolling_args (const char *arg,
08ef48c5 939 struct tui_win_info **win_to_scroll,
6ba8e26f 940 int *num_to_scroll)
c906108c 941{
6ba8e26f
AC
942 if (num_to_scroll)
943 *num_to_scroll = 0;
944 *win_to_scroll = tui_win_with_focus ();
c906108c 945
ef5eab5a
MS
946 /* First set up the default window to scroll, in case there is no
947 window name arg. */
63a33118 948 if (arg != NULL)
c906108c 949 {
f71c8822 950 char *buf_ptr;
c906108c 951
1cc6d956 952 /* Process the number of lines to scroll. */
f71c8822
TT
953 std::string copy = arg;
954 buf_ptr = &copy[0];
6ba8e26f 955 if (isdigit (*buf_ptr))
c906108c 956 {
6ba8e26f 957 char *num_str;
c906108c 958
6ba8e26f
AC
959 num_str = buf_ptr;
960 buf_ptr = strchr (buf_ptr, ' ');
63a33118 961 if (buf_ptr != NULL)
c906108c 962 {
78e8cb91 963 *buf_ptr = '\0';
6ba8e26f
AC
964 if (num_to_scroll)
965 *num_to_scroll = atoi (num_str);
966 buf_ptr++;
c906108c 967 }
6ba8e26f
AC
968 else if (num_to_scroll)
969 *num_to_scroll = atoi (num_str);
c906108c
SS
970 }
971
1cc6d956 972 /* Process the window name if one is specified. */
63a33118 973 if (buf_ptr != NULL)
c906108c 974 {
a121b7c1 975 const char *wname;
c906108c 976
78e8cb91 977 wname = skip_spaces (buf_ptr);
c906108c 978
78e8cb91 979 if (*wname != '\0')
c709a7c2 980 {
78e8cb91
TT
981 *win_to_scroll = tui_partial_win_by_name (wname);
982
983 if (*win_to_scroll == NULL)
984 error (_("Unrecognized window `%s'"), wname);
985 if (!(*win_to_scroll)->is_visible ())
986 error (_("Window is not visible"));
987 else if (*win_to_scroll == TUI_CMD_WIN)
988 *win_to_scroll = *(tui_source_windows ().begin ());
c709a7c2 989 }
c906108c 990 }
c906108c 991 }
6ba8e26f 992}
7806cea7
TT
993
994/* Function to initialize gdb commands, for tui window
995 manipulation. */
996
6c265988 997void _initialize_tui_win ();
7806cea7 998void
6c265988 999_initialize_tui_win ()
7806cea7
TT
1000{
1001 static struct cmd_list_element *tui_setlist;
1002 static struct cmd_list_element *tui_showlist;
1003 struct cmd_list_element *cmd;
1004
1005 /* Define the classes of commands.
1006 They will appear in the help list in the reverse of this order. */
1007 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
590042fc 1008 _("TUI configuration variables."),
7806cea7
TT
1009 &tui_setlist, "set tui ",
1010 0 /* allow-unknown */, &setlist);
1011 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
590042fc 1012 _("TUI configuration variables."),
7806cea7
TT
1013 &tui_showlist, "show tui ",
1014 0 /* allow-unknown */, &showlist);
1015
1016 add_com ("refresh", class_tui, tui_refresh_all_command,
89549d7f 1017 _("Refresh the terminal display."));
7806cea7
TT
1018
1019 cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1020Set the width (in characters) of tab stops.\n\
89549d7f 1021Usage: tabset N"));
7806cea7
TT
1022 deprecate_cmd (cmd, "set tui tab-width");
1023
1024 cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
ca793b96
TT
1025Set or modify the height of a specified window.\n\
1026Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n\
1027Use \"info win\" to see the names of the windows currently being displayed."));
7806cea7
TT
1028 add_com_alias ("wh", "winheight", class_tui, 0);
1029 set_cmd_completer (cmd, winheight_completer);
1030 add_info ("win", tui_all_windows_info,
283be8bf
TT
1031 _("List of all displayed windows.\n\
1032Usage: info win"));
7806cea7 1033 cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
ca793b96
TT
1034Set focus to named window or next/prev window.\n\
1035Usage: focus [WINDOW-NAME | next | prev]\n\
1036Use \"info win\" to see the names of the windows currently being displayed."));
7806cea7
TT
1037 add_com_alias ("fs", "focus", class_tui, 0);
1038 set_cmd_completer (cmd, focus_completer);
1039 add_com ("+", class_tui, tui_scroll_forward_command, _("\
1040Scroll window forward.\n\
7a27a45b
AB
1041Usage: + [N] [WIN]\n\
1042Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\
1043defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1044 add_com ("-", class_tui, tui_scroll_backward_command, _("\
1045Scroll window backward.\n\
7a27a45b
AB
1046Usage: - [N] [WIN]\n\
1047Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\
1048defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1049 add_com ("<", class_tui, tui_scroll_left_command, _("\
1050Scroll window text to the left.\n\
7a27a45b
AB
1051Usage: < [N] [WIN]\n\
1052Scroll window WIN N characters left. Both WIN and N are optional, N\n\
1053defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1054 add_com (">", class_tui, tui_scroll_right_command, _("\
1055Scroll window text to the right.\n\
7a27a45b
AB
1056Usage: > [N] [WIN]\n\
1057Scroll window WIN N characters right. Both WIN and N are optional, N\n\
1058defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1059
1060 /* Define the tui control variables. */
1061 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1062 &tui_border_kind, _("\
1063Set the kind of border for TUI windows."), _("\
1064Show the kind of border for TUI windows."), _("\
1065This variable controls the border of TUI windows:\n\
89549d7f
TT
1066 space use a white space\n\
1067 ascii use ascii characters + - | for the border\n\
1068 acs use the Alternate Character Set"),
7806cea7
TT
1069 tui_set_var_cmd,
1070 show_tui_border_kind,
1071 &tui_setlist, &tui_showlist);
1072
1073 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1074 &tui_border_mode, _("\
1075Set the attribute mode to use for the TUI window borders."), _("\
1076Show the attribute mode to use for the TUI window borders."), _("\
1077This variable controls the attributes to use for the window borders:\n\
89549d7f
TT
1078 normal normal display\n\
1079 standout use highlight mode of terminal\n\
1080 reverse use reverse video mode\n\
1081 half use half bright\n\
1082 half-standout use half bright and standout mode\n\
1083 bold use extra bright or bold\n\
1084 bold-standout use extra bright or bold with standout mode"),
7806cea7
TT
1085 tui_set_var_cmd,
1086 show_tui_border_mode,
1087 &tui_setlist, &tui_showlist);
1088
1089 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1090 &tui_active_border_mode, _("\
1091Set the attribute mode to use for the active TUI window border."), _("\
1092Show the attribute mode to use for the active TUI window border."), _("\
1093This variable controls the attributes to use for the active window border:\n\
89549d7f
TT
1094 normal normal display\n\
1095 standout use highlight mode of terminal\n\
1096 reverse use reverse video mode\n\
1097 half use half bright\n\
1098 half-standout use half bright and standout mode\n\
1099 bold use extra bright or bold\n\
1100 bold-standout use extra bright or bold with standout mode"),
7806cea7
TT
1101 tui_set_var_cmd,
1102 show_tui_active_border_mode,
1103 &tui_setlist, &tui_showlist);
1104
1105 add_setshow_zuinteger_cmd ("tab-width", no_class,
1106 &internal_tab_width, _("\
1107Set the tab width, in characters, for the TUI."), _("\
590042fc 1108Show the tab witdh, in characters, for the TUI."), _("\
7806cea7
TT
1109This variable controls how many spaces are used to display a tab character."),
1110 tui_set_tab_width, tui_show_tab_width,
1111 &tui_setlist, &tui_showlist);
45e42163
TT
1112
1113 add_setshow_boolean_cmd ("tui-resize-message", class_maintenance,
1114 &resize_message, _("\
1115Set TUI resize messaging."), _("\
1116Show TUI resize messaging."), _("\
1117When enabled GDB will print a message when the terminal is resized."),
1118 nullptr,
1119 show_tui_resize_message,
1120 &maintenance_set_cmdlist,
1121 &maintenance_show_cmdlist);
d1da6b01
TT
1122
1123 add_setshow_boolean_cmd ("compact-source", class_tui,
1124 &compact_source, _("\
1125Set whether the TUI source window is compact."), _("\
1126Show whether the TUI source window is compact."), _("\
1127This variable controls whether the TUI source window is shown\n\
1128in a compact form. The compact form puts the source closer to\n\
1129the line numbers and uses less horizontal space."),
1130 tui_set_compact_source, tui_show_compact_source,
1131 &tui_setlist, &tui_showlist);
a2a7af0c
TT
1132
1133 tui_border_style.changed.attach (tui_rehighlight_all);
1134 tui_active_border_style.changed.attach (tui_rehighlight_all);
7806cea7 1135}
This page took 2.310367 seconds and 4 git commands to generate.