Introduce async-event.[ch]
[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"
c4ef48c6 36#include "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
313static void
981a3fb3 314tui_command (const char *args, int from_tty)
10f59415 315{
a3f17187
AC
316 printf_unfiltered (_("\"tui\" must be followed by the name of a "
317 "tui command.\n"));
635c7e8a 318 help_list (tuilist, "tui ", all_commands, gdb_stdout);
10f59415
SC
319}
320
321struct cmd_list_element **
da745b36 322tui_get_cmd_list (void)
10f59415
SC
323{
324 if (tuilist == 0)
325 add_prefix_cmd ("tui", class_tui, tui_command,
1bedd215 326 _("Text User Interface commands."),
10f59415
SC
327 &tuilist, "tui ", 0, &cmdlist);
328 return &tuilist;
329}
330
6cdb25f4
EZ
331/* The set_func hook of "set tui ..." commands that affect the window
332 borders on the TUI display. */
3b5c1d49
SM
333
334static void
eb4c3f4a
TT
335tui_set_var_cmd (const char *null_args,
336 int from_tty, struct cmd_list_element *c)
6cdb25f4
EZ
337{
338 if (tui_update_variables () && tui_active)
339 tui_rehighlight_all ();
340}
341
45e42163
TT
342\f
343
344/* True if TUI resizes should print a message. This is used by the
345 test suite. */
346
347static bool resize_message;
348
349static void
350show_tui_resize_message (struct ui_file *file, int from_tty,
351 struct cmd_list_element *c, const char *value)
352{
353 fprintf_filtered (file, _("TUI resize messaging is %s.\n"), value);
354}
355
356\f
357
97605e61
AB
358/* Generic window name completion function. Complete window name pointed
359 to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
360 window names 'next' and 'prev' will also be considered as possible
361 completions of the window name. */
2e52ae68 362
eb3ff9a5
PA
363static void
364window_name_completer (completion_tracker &tracker,
365 int include_next_prev_p,
97605e61 366 const char *text, const char *word)
2e52ae68 367{
625ad440 368 std::vector<const char *> completion_name_vec;
2e52ae68 369
1ce3e844 370 for (tui_win_info *win_info : all_tui_windows ())
2e52ae68
PP
371 {
372 const char *completion_name = NULL;
373
374 /* We can't focus on an invisible window. */
2d83e710 375 if (!win_info->is_visible ())
2e52ae68
PP
376 continue;
377
1ce3e844 378 completion_name = win_info->name ();
150375dc 379 gdb_assert (completion_name != NULL);
625ad440 380 completion_name_vec.push_back (completion_name);
2e52ae68
PP
381 }
382
383 /* If no windows are considered visible then the TUI has not yet been
384 initialized. But still "focus src" and "focus cmd" will work because
385 invoking the focus command will entail initializing the TUI which sets the
416eb92d 386 default layout to "src". */
625ad440 387 if (completion_name_vec.empty ())
2e52ae68 388 {
625ad440
SM
389 completion_name_vec.push_back (SRC_NAME);
390 completion_name_vec.push_back (CMD_NAME);
2e52ae68
PP
391 }
392
97605e61
AB
393 if (include_next_prev_p)
394 {
625ad440
SM
395 completion_name_vec.push_back ("next");
396 completion_name_vec.push_back ("prev");
97605e61 397 }
2e52ae68 398
2e52ae68 399
625ad440
SM
400 completion_name_vec.push_back (NULL);
401 complete_on_enum (tracker, completion_name_vec.data (), text, word);
2e52ae68
PP
402}
403
97605e61
AB
404/* Complete possible window names to focus on. TEXT is the complete text
405 entered so far, WORD is the word currently being completed. */
406
eb3ff9a5 407static void
97605e61 408focus_completer (struct cmd_list_element *ignore,
eb3ff9a5
PA
409 completion_tracker &tracker,
410 const char *text, const char *word)
97605e61 411{
eb3ff9a5 412 window_name_completer (tracker, 1, text, word);
97605e61
AB
413}
414
415/* Complete possible window names for winheight command. TEXT is the
416 complete text entered so far, WORD is the word currently being
417 completed. */
418
eb3ff9a5 419static void
97605e61 420winheight_completer (struct cmd_list_element *ignore,
eb3ff9a5 421 completion_tracker &tracker,
97605e61
AB
422 const char *text, const char *word)
423{
424 /* The first word is the window name. That we can complete. Subsequent
425 words can't be completed. */
426 if (word != text)
eb3ff9a5 427 return;
97605e61 428
eb3ff9a5 429 window_name_completer (tracker, 0, text, word);
97605e61
AB
430}
431
3e752b04
SC
432/* Update gdb's knowledge of the terminal size. */
433void
d02c80cd 434tui_update_gdb_sizes (void)
3e752b04 435{
d6e5e7f7
PP
436 int width, height;
437
438 if (tui_active)
439 {
cb2ce893
TT
440 width = TUI_CMD_WIN->width;
441 height = TUI_CMD_WIN->height;
d6e5e7f7
PP
442 }
443 else
444 {
445 width = tui_term_width ();
446 height = tui_term_height ();
447 }
448
449 set_screen_width_and_height (width, height);
3e752b04
SC
450}
451
c906108c 452
c906108c 453void
13446e05 454tui_win_info::forward_scroll (int num_to_scroll)
c906108c 455{
13446e05 456 if (num_to_scroll == 0)
cb2ce893 457 num_to_scroll = height - 3;
c906108c 458
c3bd716f 459 do_scroll_vertical (num_to_scroll);
a21fcd8f 460}
c906108c 461
c906108c 462void
13446e05 463tui_win_info::backward_scroll (int num_to_scroll)
c906108c 464{
13446e05 465 if (num_to_scroll == 0)
cb2ce893 466 num_to_scroll = height - 3;
13446e05 467
c3bd716f 468 do_scroll_vertical (-num_to_scroll);
a21fcd8f 469}
c906108c
SS
470
471
c906108c 472void
13446e05 473tui_win_info::left_scroll (int num_to_scroll)
c906108c 474{
13446e05
TT
475 if (num_to_scroll == 0)
476 num_to_scroll = 1;
477
c3bd716f 478 do_scroll_horizontal (num_to_scroll);
a21fcd8f 479}
c906108c
SS
480
481
c906108c 482void
13446e05 483tui_win_info::right_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);
e8b915dc 489}
c906108c
SS
490
491
c906108c 492void
a21fcd8f 493tui_refresh_all_win (void)
c906108c 494{
3e266828 495 clearok (curscr, TRUE);
1ce3e844 496 tui_refresh_all ();
bc712bbf 497}
c906108c 498
6cdb25f4
EZ
499void
500tui_rehighlight_all (void)
501{
1ce3e844 502 for (tui_win_info *win_info : all_tui_windows ())
b4ef5aeb 503 win_info->check_and_display_highlight_if_needed ();
6cdb25f4 504}
c906108c 505
b021a221 506/* Resize all the windows based on the terminal size. This function
ae2b5380 507 gets called from within the readline SIGWINCH handler. */
c906108c 508void
6ba8e26f 509tui_resize_all (void)
c906108c 510{
6ba8e26f 511 int height_diff, width_diff;
9255ee31 512 int screenheight, screenwidth;
c906108c 513
9255ee31 514 rl_get_screen_size (&screenheight, &screenwidth);
6ba8e26f
AC
515 width_diff = screenwidth - tui_term_width ();
516 height_diff = screenheight - tui_term_height ();
517 if (height_diff || width_diff)
c906108c 518 {
5b6fe301 519 struct tui_win_info *win_with_focus = tui_win_with_focus ();
c906108c 520
10f59415
SC
521#ifdef HAVE_RESIZE_TERM
522 resize_term (screenheight, screenwidth);
523#endif
1cc6d956 524 /* Turn keypad off while we resize. */
6ba8e26f 525 if (win_with_focus != TUI_CMD_WIN)
7523da63 526 keypad (TUI_CMD_WIN->handle.get (), FALSE);
3e752b04 527 tui_update_gdb_sizes ();
dd1abb8c
AC
528 tui_set_term_height_to (screenheight);
529 tui_set_term_width_to (screenwidth);
3d979945 530
c366c1f0
TT
531 /* erase + clearok are used instead of a straightforward clear as
532 AIX 5.3 does not define clear. */
533 erase ();
534 clearok (curscr, TRUE);
3d979945 535 tui_apply_current_layout ();
1cc6d956
MS
536 /* Turn keypad back on, unless focus is in the command
537 window. */
6ba8e26f 538 if (win_with_focus != TUI_CMD_WIN)
7523da63 539 keypad (TUI_CMD_WIN->handle.get (), TRUE);
c906108c 540 }
6ba8e26f 541}
c906108c 542
2c0b251b 543#ifdef SIGWINCH
c4ef48c6
PP
544/* Token for use by TUI's asynchronous SIGWINCH handler. */
545static struct async_signal_handler *tui_sigwinch_token;
546
547/* TUI's SIGWINCH signal handler. */
2c0b251b 548static void
6ba8e26f 549tui_sigwinch_handler (int signal)
c906108c 550{
c4ef48c6 551 mark_async_signal_handler (tui_sigwinch_token);
9abd8a65 552 tui_set_win_resized_to (true);
6ba8e26f 553}
c4ef48c6
PP
554
555/* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
556static void
557tui_async_resize_screen (gdb_client_data arg)
558{
a88d0bb3
PP
559 rl_resize_terminal ();
560
c4ef48c6 561 if (!tui_active)
a88d0bb3
PP
562 {
563 int screen_height, screen_width;
c4ef48c6 564
a88d0bb3
PP
565 rl_get_screen_size (&screen_height, &screen_width);
566 set_screen_width_and_height (screen_width, screen_height);
567
568 /* win_resized is left set so that the next call to tui_enable()
569 resizes the TUI windows. */
570 }
571 else
572 {
9abd8a65 573 tui_set_win_resized_to (false);
a88d0bb3
PP
574 tui_resize_all ();
575 tui_refresh_all_win ();
576 tui_update_gdb_sizes ();
45e42163
TT
577 if (resize_message)
578 {
579 static int count;
580 printf_unfiltered ("@@ resize done %d, size = %dx%d\n", count,
581 tui_term_width (), tui_term_height ());
582 ++count;
583 }
a88d0bb3
PP
584 tui_redisplay_readline ();
585 }
c4ef48c6 586}
2c0b251b 587#endif
c906108c 588
c4ef48c6
PP
589/* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
590 uninstalled when we exit TUI, so the handler should not assume that TUI is
591 always active. */
9612b5ec
UW
592void
593tui_initialize_win (void)
594{
595#ifdef SIGWINCH
c4ef48c6
PP
596 tui_sigwinch_token
597 = create_async_signal_handler (tui_async_resize_screen, NULL);
598
599 {
9612b5ec 600#ifdef HAVE_SIGACTION
c4ef48c6 601 struct sigaction old_winch;
1c5313c5 602
c4ef48c6
PP
603 memset (&old_winch, 0, sizeof (old_winch));
604 old_winch.sa_handler = &tui_sigwinch_handler;
a344fc09 605#ifdef SA_RESTART
c4ef48c6 606 old_winch.sa_flags = SA_RESTART;
a344fc09 607#endif
c4ef48c6 608 sigaction (SIGWINCH, &old_winch, NULL);
9612b5ec 609#else
c4ef48c6 610 signal (SIGWINCH, &tui_sigwinch_handler);
9612b5ec 611#endif
c4ef48c6 612 }
9612b5ec
UW
613#endif
614}
c906108c
SS
615
616
c906108c 617static void
0b39b52e 618tui_scroll_forward_command (const char *arg, int from_tty)
c906108c 619{
6ba8e26f 620 int num_to_scroll = 1;
5b6fe301 621 struct tui_win_info *win_to_scroll;
c906108c 622
1854bb21
SC
623 /* Make sure the curses mode is enabled. */
624 tui_enable ();
63a33118 625 if (arg == NULL)
cafb3438 626 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 627 else
6ba8e26f 628 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 629 win_to_scroll->forward_scroll (num_to_scroll);
e8b915dc 630}
c906108c
SS
631
632
c906108c 633static void
0b39b52e 634tui_scroll_backward_command (const char *arg, int from_tty)
c906108c 635{
6ba8e26f 636 int num_to_scroll = 1;
5b6fe301 637 struct tui_win_info *win_to_scroll;
c906108c 638
1854bb21
SC
639 /* Make sure the curses mode is enabled. */
640 tui_enable ();
63a33118 641 if (arg == NULL)
cafb3438 642 parse_scrolling_args (arg, &win_to_scroll, NULL);
c906108c 643 else
6ba8e26f 644 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 645 win_to_scroll->backward_scroll (num_to_scroll);
e8b915dc 646}
c906108c
SS
647
648
c906108c 649static void
0b39b52e 650tui_scroll_left_command (const char *arg, int from_tty)
c906108c 651{
6ba8e26f 652 int num_to_scroll;
5b6fe301 653 struct tui_win_info *win_to_scroll;
c906108c 654
1854bb21
SC
655 /* Make sure the curses mode is enabled. */
656 tui_enable ();
6ba8e26f 657 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 658 win_to_scroll->left_scroll (num_to_scroll);
e8b915dc 659}
c906108c
SS
660
661
c906108c 662static void
0b39b52e 663tui_scroll_right_command (const char *arg, int from_tty)
c906108c 664{
6ba8e26f 665 int num_to_scroll;
5b6fe301 666 struct tui_win_info *win_to_scroll;
c906108c 667
1854bb21
SC
668 /* Make sure the curses mode is enabled. */
669 tui_enable ();
6ba8e26f 670 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
13446e05 671 win_to_scroll->right_scroll (num_to_scroll);
e8b915dc 672}
c906108c
SS
673
674
9f6ad286
TT
675/* Answer the window represented by name. */
676static struct tui_win_info *
677tui_partial_win_by_name (gdb::string_view name)
678{
e098d18c
TT
679 struct tui_win_info *best = nullptr;
680
9f6ad286
TT
681 if (name != NULL)
682 {
683 for (tui_win_info *item : all_tui_windows ())
684 {
685 const char *cur_name = item->name ();
686
e098d18c 687 if (name == cur_name)
9f6ad286 688 return item;
e098d18c
TT
689 if (startswith (cur_name, name))
690 {
691 if (best != nullptr)
692 error (_("Window name \"%*s\" is ambiguous"),
693 (int) name.size (), name.data ());
694 best = item;
695 }
9f6ad286
TT
696 }
697 }
698
e098d18c 699 return best;
9f6ad286
TT
700}
701
6ba8e26f 702/* Set focus to the window named by 'arg'. */
c906108c 703static void
01aeb396 704tui_set_focus_command (const char *arg, int from_tty)
c906108c 705{
01aeb396
TT
706 tui_enable ();
707
ca793b96
TT
708 if (arg == NULL)
709 error_no_arg (_("name of window to focus"));
c906108c 710
ca793b96 711 struct tui_win_info *win_info = NULL;
c906108c 712
ca793b96
TT
713 if (subset_compare (arg, "next"))
714 win_info = tui_next_win (tui_win_with_focus ());
715 else if (subset_compare (arg, "prev"))
716 win_info = tui_prev_win (tui_win_with_focus ());
c906108c 717 else
ca793b96
TT
718 win_info = tui_partial_win_by_name (arg);
719
720 if (win_info == NULL)
721 error (_("Unrecognized window name \"%s\""), arg);
722 if (!win_info->is_visible ())
723 error (_("Window \"%s\" is not visible"), arg);
724
725 tui_set_win_focus_to (win_info);
726 keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
727 printf_filtered (_("Focus set to %s window.\n"),
728 tui_win_with_focus ()->name ());
6ba8e26f 729}
c906108c 730
c906108c 731static void
1d12d88f 732tui_all_windows_info (const char *arg, int from_tty)
c906108c 733{
82e3b564
TT
734 if (!tui_active)
735 {
736 printf_filtered (_("The TUI is not active.\n"));
737 return;
738 }
739
5b6fe301 740 struct tui_win_info *win_with_focus = tui_win_with_focus ();
25a2915e
TT
741 struct ui_out *uiout = current_uiout;
742
743 ui_out_emit_table table_emitter (uiout, 3, -1, "tui-windows");
744 uiout->table_header (10, ui_left, "name", "Name");
745 uiout->table_header (5, ui_right, "lines", "Lines");
746 uiout->table_header (10, ui_left, "focus", "Focus");
747 uiout->table_body ();
c906108c 748
1ce3e844 749 for (tui_win_info *win_info : all_tui_windows ())
2d83e710 750 if (win_info->is_visible ())
c906108c 751 {
25a2915e
TT
752 ui_out_emit_tuple tuple_emitter (uiout, nullptr);
753
754 uiout->field_string ("name", win_info->name ());
755 uiout->field_signed ("lines", win_info->height);
1ce3e844 756 if (win_with_focus == win_info)
25a2915e 757 uiout->field_string ("focus", _("(has focus)"));
c906108c 758 else
25a2915e
TT
759 uiout->field_skip ("focus");
760 uiout->text ("\n");
c906108c 761 }
6ba8e26f 762}
c906108c
SS
763
764
c906108c 765static void
0b39b52e 766tui_refresh_all_command (const char *arg, int from_tty)
c906108c 767{
1854bb21
SC
768 /* Make sure the curses mode is enabled. */
769 tui_enable ();
770
a21fcd8f 771 tui_refresh_all_win ();
c906108c
SS
772}
773
7806cea7
TT
774/* The tab width that should be used by the TUI. */
775
776unsigned int tui_tab_width = DEFAULT_TAB_LEN;
777
778/* The tab width as set by the user. */
779
780static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
781
d83f1fe6
TT
782/* After the tab width is set, call this to update the relevant
783 windows. */
784
785static void
786update_tab_width ()
787{
1ce3e844 788 for (tui_win_info *win_info : all_tui_windows ())
7806cea7 789 {
2d83e710 790 if (win_info->is_visible ())
1ce3e844 791 win_info->update_tab_width ();
7806cea7
TT
792 }
793}
794
795/* Callback for "set tui tab-width". */
796
797static void
798tui_set_tab_width (const char *ignore,
799 int from_tty, struct cmd_list_element *c)
800{
801 if (internal_tab_width == 0)
802 {
803 internal_tab_width = tui_tab_width;
804 error (_("Tab width must not be 0"));
805 }
806
807 tui_tab_width = internal_tab_width;
808 update_tab_width ();
809}
810
811/* Callback for "show tui tab-width". */
812
813static void
814tui_show_tab_width (struct ui_file *file, int from_tty,
815 struct cmd_list_element *c, const char *value)
816{
817 fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value);
818
819}
c906108c 820
d1da6b01
TT
821/* See tui-win.h. */
822
823bool compact_source = false;
824
825/* Callback for "set tui compact-source". */
826
827static void
828tui_set_compact_source (const char *ignore, int from_tty,
829 struct cmd_list_element *c)
830{
831 if (TUI_SRC_WIN != nullptr)
832 TUI_SRC_WIN->refill ();
833}
834
835/* Callback for "show tui compact-source". */
836
837static void
838tui_show_compact_source (struct ui_file *file, int from_tty,
839 struct cmd_list_element *c, const char *value)
840{
841 printf_filtered (_("TUI source window compactness is %s.\n"), value);
842}
843
c54da50d 844/* Set the tab width of the specified window. */
c906108c 845static void
0b39b52e 846tui_set_tab_width_command (const char *arg, int from_tty)
c906108c 847{
1854bb21
SC
848 /* Make sure the curses mode is enabled. */
849 tui_enable ();
63a33118 850 if (arg != NULL)
c906108c
SS
851 {
852 int ts;
853
854 ts = atoi (arg);
7806cea7
TT
855 if (ts <= 0)
856 warning (_("Tab widths greater than 0 must be specified."));
857 else
cb86fcc1 858 {
7806cea7
TT
859 internal_tab_width = ts;
860 tui_tab_width = ts;
861
862 update_tab_width ();
cb86fcc1 863 }
c906108c 864 }
6ba8e26f 865}
c906108c
SS
866
867
1cc6d956 868/* Set the height of the specified window. */
c906108c 869static void
4dde7b34 870tui_set_win_height_command (const char *arg, int from_tty)
c906108c 871{
1854bb21
SC
872 /* Make sure the curses mode is enabled. */
873 tui_enable ();
ca793b96
TT
874 if (arg == NULL)
875 error_no_arg (_("name of window"));
c906108c 876
ca793b96
TT
877 const char *buf = arg;
878 const char *buf_ptr = buf;
879 int new_height;
880 struct tui_win_info *win_info;
c906108c 881
ca793b96 882 buf_ptr = skip_to_space (buf_ptr);
78e8cb91 883
ca793b96
TT
884 /* Validate the window name. */
885 gdb::string_view wname (buf, buf_ptr - buf);
886 win_info = tui_partial_win_by_name (wname);
78e8cb91 887
ca793b96
TT
888 if (win_info == NULL)
889 error (_("Unrecognized window name \"%s\""), arg);
890 if (!win_info->is_visible ())
891 error (_("Window \"%s\" is not visible"), arg);
892
893 /* Process the size. */
894 buf_ptr = skip_spaces (buf_ptr);
895
896 if (*buf_ptr != '\0')
897 {
898 bool negate = false;
899 bool fixed_size = true;
900 int input_no;;
901
902 if (*buf_ptr == '+' || *buf_ptr == '-')
903 {
904 if (*buf_ptr == '-')
905 negate = true;
906 fixed_size = false;
907 buf_ptr++;
908 }
909 input_no = atoi (buf_ptr);
910 if (input_no > 0)
911 {
912 if (negate)
913 input_no *= (-1);
914 if (fixed_size)
915 new_height = input_no;
916 else
917 new_height = win_info->height + input_no;
918
919 /* Now change the window's height, and adjust
920 all other windows around it. */
921 tui_adjust_window_height (win_info, new_height);
922 tui_update_gdb_sizes ();
c906108c
SS
923 }
924 else
ca793b96 925 error (_("Invalid window height specified"));
c906108c 926 }
6ba8e26f 927}
c906108c 928
5fcee43a 929/* See tui-data.h. */
c906108c 930
8903bd8a
TT
931int
932tui_win_info::max_height () const
933{
934 return tui_term_height () - 2;
935}
936
7c043ba6
TT
937/* See tui-data.h. */
938
939int
940tui_gen_win_info::max_width () const
941{
942 return tui_term_width () - 2;
943}
944
c906108c 945static void
0b39b52e 946parse_scrolling_args (const char *arg,
08ef48c5 947 struct tui_win_info **win_to_scroll,
6ba8e26f 948 int *num_to_scroll)
c906108c 949{
6ba8e26f
AC
950 if (num_to_scroll)
951 *num_to_scroll = 0;
952 *win_to_scroll = tui_win_with_focus ();
c906108c 953
ef5eab5a
MS
954 /* First set up the default window to scroll, in case there is no
955 window name arg. */
63a33118 956 if (arg != NULL)
c906108c 957 {
f71c8822 958 char *buf_ptr;
c906108c 959
1cc6d956 960 /* Process the number of lines to scroll. */
f71c8822
TT
961 std::string copy = arg;
962 buf_ptr = &copy[0];
6ba8e26f 963 if (isdigit (*buf_ptr))
c906108c 964 {
6ba8e26f 965 char *num_str;
c906108c 966
6ba8e26f
AC
967 num_str = buf_ptr;
968 buf_ptr = strchr (buf_ptr, ' ');
63a33118 969 if (buf_ptr != NULL)
c906108c 970 {
78e8cb91 971 *buf_ptr = '\0';
6ba8e26f
AC
972 if (num_to_scroll)
973 *num_to_scroll = atoi (num_str);
974 buf_ptr++;
c906108c 975 }
6ba8e26f
AC
976 else if (num_to_scroll)
977 *num_to_scroll = atoi (num_str);
c906108c
SS
978 }
979
1cc6d956 980 /* Process the window name if one is specified. */
63a33118 981 if (buf_ptr != NULL)
c906108c 982 {
a121b7c1 983 const char *wname;
c906108c 984
78e8cb91 985 wname = skip_spaces (buf_ptr);
c906108c 986
78e8cb91 987 if (*wname != '\0')
c709a7c2 988 {
78e8cb91
TT
989 *win_to_scroll = tui_partial_win_by_name (wname);
990
991 if (*win_to_scroll == NULL)
992 error (_("Unrecognized window `%s'"), wname);
993 if (!(*win_to_scroll)->is_visible ())
994 error (_("Window is not visible"));
995 else if (*win_to_scroll == TUI_CMD_WIN)
996 *win_to_scroll = *(tui_source_windows ().begin ());
c709a7c2 997 }
c906108c 998 }
c906108c 999 }
6ba8e26f 1000}
7806cea7
TT
1001
1002/* Function to initialize gdb commands, for tui window
1003 manipulation. */
1004
6c265988 1005void _initialize_tui_win ();
7806cea7 1006void
6c265988 1007_initialize_tui_win ()
7806cea7
TT
1008{
1009 static struct cmd_list_element *tui_setlist;
1010 static struct cmd_list_element *tui_showlist;
1011 struct cmd_list_element *cmd;
1012
1013 /* Define the classes of commands.
1014 They will appear in the help list in the reverse of this order. */
1015 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
590042fc 1016 _("TUI configuration variables."),
7806cea7
TT
1017 &tui_setlist, "set tui ",
1018 0 /* allow-unknown */, &setlist);
1019 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
590042fc 1020 _("TUI configuration variables."),
7806cea7
TT
1021 &tui_showlist, "show tui ",
1022 0 /* allow-unknown */, &showlist);
1023
1024 add_com ("refresh", class_tui, tui_refresh_all_command,
89549d7f 1025 _("Refresh the terminal display."));
7806cea7
TT
1026
1027 cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1028Set the width (in characters) of tab stops.\n\
89549d7f 1029Usage: tabset N"));
7806cea7
TT
1030 deprecate_cmd (cmd, "set tui tab-width");
1031
1032 cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
ca793b96
TT
1033Set or modify the height of a specified window.\n\
1034Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n\
1035Use \"info win\" to see the names of the windows currently being displayed."));
7806cea7
TT
1036 add_com_alias ("wh", "winheight", class_tui, 0);
1037 set_cmd_completer (cmd, winheight_completer);
1038 add_info ("win", tui_all_windows_info,
283be8bf
TT
1039 _("List of all displayed windows.\n\
1040Usage: info win"));
7806cea7 1041 cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
ca793b96
TT
1042Set focus to named window or next/prev window.\n\
1043Usage: focus [WINDOW-NAME | next | prev]\n\
1044Use \"info win\" to see the names of the windows currently being displayed."));
7806cea7
TT
1045 add_com_alias ("fs", "focus", class_tui, 0);
1046 set_cmd_completer (cmd, focus_completer);
1047 add_com ("+", class_tui, tui_scroll_forward_command, _("\
1048Scroll window forward.\n\
7a27a45b
AB
1049Usage: + [N] [WIN]\n\
1050Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\
1051defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1052 add_com ("-", class_tui, tui_scroll_backward_command, _("\
1053Scroll window backward.\n\
7a27a45b
AB
1054Usage: - [N] [WIN]\n\
1055Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\
1056defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1057 add_com ("<", class_tui, tui_scroll_left_command, _("\
1058Scroll window text to the left.\n\
7a27a45b
AB
1059Usage: < [N] [WIN]\n\
1060Scroll window WIN N characters left. Both WIN and N are optional, N\n\
1061defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1062 add_com (">", class_tui, tui_scroll_right_command, _("\
1063Scroll window text to the right.\n\
7a27a45b
AB
1064Usage: > [N] [WIN]\n\
1065Scroll window WIN N characters right. Both WIN and N are optional, N\n\
1066defaults to 1, and WIN defaults to the currently focused window."));
7806cea7
TT
1067
1068 /* Define the tui control variables. */
1069 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1070 &tui_border_kind, _("\
1071Set the kind of border for TUI windows."), _("\
1072Show the kind of border for TUI windows."), _("\
1073This variable controls the border of TUI windows:\n\
89549d7f
TT
1074 space use a white space\n\
1075 ascii use ascii characters + - | for the border\n\
1076 acs use the Alternate Character Set"),
7806cea7
TT
1077 tui_set_var_cmd,
1078 show_tui_border_kind,
1079 &tui_setlist, &tui_showlist);
1080
1081 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1082 &tui_border_mode, _("\
1083Set the attribute mode to use for the TUI window borders."), _("\
1084Show the attribute mode to use for the TUI window borders."), _("\
1085This variable controls the attributes to use for the window borders:\n\
89549d7f
TT
1086 normal normal display\n\
1087 standout use highlight mode of terminal\n\
1088 reverse use reverse video mode\n\
1089 half use half bright\n\
1090 half-standout use half bright and standout mode\n\
1091 bold use extra bright or bold\n\
1092 bold-standout use extra bright or bold with standout mode"),
7806cea7
TT
1093 tui_set_var_cmd,
1094 show_tui_border_mode,
1095 &tui_setlist, &tui_showlist);
1096
1097 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1098 &tui_active_border_mode, _("\
1099Set the attribute mode to use for the active TUI window border."), _("\
1100Show the attribute mode to use for the active TUI window border."), _("\
1101This variable controls the attributes to use for the active window border:\n\
89549d7f
TT
1102 normal normal display\n\
1103 standout use highlight mode of terminal\n\
1104 reverse use reverse video mode\n\
1105 half use half bright\n\
1106 half-standout use half bright and standout mode\n\
1107 bold use extra bright or bold\n\
1108 bold-standout use extra bright or bold with standout mode"),
7806cea7
TT
1109 tui_set_var_cmd,
1110 show_tui_active_border_mode,
1111 &tui_setlist, &tui_showlist);
1112
1113 add_setshow_zuinteger_cmd ("tab-width", no_class,
1114 &internal_tab_width, _("\
1115Set the tab width, in characters, for the TUI."), _("\
590042fc 1116Show the tab witdh, in characters, for the TUI."), _("\
7806cea7
TT
1117This variable controls how many spaces are used to display a tab character."),
1118 tui_set_tab_width, tui_show_tab_width,
1119 &tui_setlist, &tui_showlist);
45e42163
TT
1120
1121 add_setshow_boolean_cmd ("tui-resize-message", class_maintenance,
1122 &resize_message, _("\
1123Set TUI resize messaging."), _("\
1124Show TUI resize messaging."), _("\
1125When enabled GDB will print a message when the terminal is resized."),
1126 nullptr,
1127 show_tui_resize_message,
1128 &maintenance_set_cmdlist,
1129 &maintenance_show_cmdlist);
d1da6b01
TT
1130
1131 add_setshow_boolean_cmd ("compact-source", class_tui,
1132 &compact_source, _("\
1133Set whether the TUI source window is compact."), _("\
1134Show whether the TUI source window is compact."), _("\
1135This variable controls whether the TUI source window is shown\n\
1136in a compact form. The compact form puts the source closer to\n\
1137the line numbers and uses less horizontal space."),
1138 tui_set_compact_source, tui_show_compact_source,
1139 &tui_setlist, &tui_showlist);
a2a7af0c
TT
1140
1141 tui_border_style.changed.attach (tui_rehighlight_all);
1142 tui_active_border_style.changed.attach (tui_rehighlight_all);
7806cea7 1143}
This page took 2.794947 seconds and 4 git commands to generate.