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