tui-win.c revision 1.1.1.9 1 1.1 christos /* TUI window generic functions.
2 1.1 christos
3 1.1.1.9 christos Copyright (C) 1998-2024 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos Contributed by Hewlett-Packard Company.
6 1.1 christos
7 1.1 christos This file is part of GDB.
8 1.1 christos
9 1.1 christos This program is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3 of the License, or
12 1.1 christos (at your option) any later version.
13 1.1 christos
14 1.1 christos This program is distributed in the hope that it will be useful,
15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 1.1 christos GNU General Public License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 1.1 christos
22 1.1 christos /* This module contains procedures for handling tui window functions
23 1.1 christos like resize, scrolling, scrolling, changing focus, etc.
24 1.1 christos
25 1.1 christos Author: Susan B. Macchia */
26 1.1 christos
27 1.1 christos #include "command.h"
28 1.1 christos #include "symtab.h"
29 1.1 christos #include "breakpoint.h"
30 1.1 christos #include "frame.h"
31 1.1 christos #include "cli/cli-cmds.h"
32 1.1.1.7 christos #include "cli/cli-style.h"
33 1.1 christos #include "top.h"
34 1.1 christos #include "source.h"
35 1.1.1.7 christos #include "gdbsupport/event-loop.h"
36 1.1.1.7 christos #include "async-event.h"
37 1.1.1.9 christos #include "utils.h"
38 1.1 christos
39 1.1 christos #include "tui/tui.h"
40 1.1.1.3 christos #include "tui/tui-io.h"
41 1.1.1.7 christos #include "tui/tui-command.h"
42 1.1 christos #include "tui/tui-data.h"
43 1.1.1.7 christos #include "tui/tui-layout.h"
44 1.1 christos #include "tui/tui-wingeneral.h"
45 1.1.1.9 christos #include "tui/tui-status.h"
46 1.1 christos #include "tui/tui-regs.h"
47 1.1 christos #include "tui/tui-disasm.h"
48 1.1 christos #include "tui/tui-source.h"
49 1.1 christos #include "tui/tui-winsource.h"
50 1.1 christos #include "tui/tui-win.h"
51 1.1 christos
52 1.1 christos #include "gdb_curses.h"
53 1.1 christos #include <ctype.h>
54 1.1 christos #include "readline/readline.h"
55 1.1.1.9 christos #include <string_view>
56 1.1 christos
57 1.1 christos #include <signal.h>
58 1.1 christos
59 1.1.1.6 christos static void tui_set_tab_width_command (const char *, int);
60 1.1.1.6 christos static void tui_refresh_all_command (const char *, int);
61 1.1.1.6 christos static void tui_all_windows_info (const char *, int);
62 1.1.1.6 christos static void tui_scroll_forward_command (const char *, int);
63 1.1.1.6 christos static void tui_scroll_backward_command (const char *, int);
64 1.1.1.6 christos static void tui_scroll_left_command (const char *, int);
65 1.1.1.6 christos static void tui_scroll_right_command (const char *, int);
66 1.1.1.6 christos static void parse_scrolling_args (const char *,
67 1.1 christos struct tui_win_info **,
68 1.1 christos int *);
69 1.1 christos
70 1.1 christos
71 1.1 christos #ifndef ACS_LRCORNER
72 1.1 christos # define ACS_LRCORNER '+'
73 1.1 christos #endif
74 1.1 christos #ifndef ACS_LLCORNER
75 1.1 christos # define ACS_LLCORNER '+'
76 1.1 christos #endif
77 1.1 christos #ifndef ACS_ULCORNER
78 1.1 christos # define ACS_ULCORNER '+'
79 1.1 christos #endif
80 1.1 christos #ifndef ACS_URCORNER
81 1.1 christos # define ACS_URCORNER '+'
82 1.1 christos #endif
83 1.1 christos #ifndef ACS_HLINE
84 1.1 christos # define ACS_HLINE '-'
85 1.1 christos #endif
86 1.1 christos #ifndef ACS_VLINE
87 1.1 christos # define ACS_VLINE '|'
88 1.1 christos #endif
89 1.1 christos
90 1.1 christos /* Possible values for tui-border-kind variable. */
91 1.1 christos static const char *const tui_border_kind_enums[] = {
92 1.1 christos "space",
93 1.1 christos "ascii",
94 1.1 christos "acs",
95 1.1 christos NULL
96 1.1 christos };
97 1.1 christos
98 1.1 christos /* Possible values for tui-border-mode and tui-active-border-mode. */
99 1.1 christos static const char *const tui_border_mode_enums[] = {
100 1.1 christos "normal",
101 1.1 christos "standout",
102 1.1 christos "reverse",
103 1.1 christos "half",
104 1.1 christos "half-standout",
105 1.1 christos "bold",
106 1.1 christos "bold-standout",
107 1.1 christos NULL
108 1.1 christos };
109 1.1 christos
110 1.1 christos struct tui_translate
111 1.1 christos {
112 1.1 christos const char *name;
113 1.1 christos int value;
114 1.1 christos };
115 1.1 christos
116 1.1 christos /* Translation table for border-mode variables.
117 1.1.1.9 christos The list of values must be terminated by a NULL. */
118 1.1.1.7 christos static struct tui_translate tui_border_mode_translate[] = {
119 1.1 christos { "normal", A_NORMAL },
120 1.1 christos { "standout", A_STANDOUT },
121 1.1 christos { "reverse", A_REVERSE },
122 1.1 christos { "half", A_DIM },
123 1.1 christos { "half-standout", A_DIM | A_STANDOUT },
124 1.1 christos { "bold", A_BOLD },
125 1.1 christos { "bold-standout", A_BOLD | A_STANDOUT },
126 1.1.1.9 christos { 0, 0 }
127 1.1 christos };
128 1.1 christos
129 1.1.1.9 christos /* Translation tables for border-kind (acs excluded), one for vline, hline and
130 1.1.1.9 christos corners (see wborder, border curses operations). */
131 1.1.1.7 christos static struct tui_translate tui_border_kind_translate_vline[] = {
132 1.1 christos { "space", ' ' },
133 1.1 christos { "ascii", '|' },
134 1.1.1.9 christos { 0, 0 }
135 1.1 christos };
136 1.1 christos
137 1.1.1.7 christos static struct tui_translate tui_border_kind_translate_hline[] = {
138 1.1 christos { "space", ' ' },
139 1.1 christos { "ascii", '-' },
140 1.1.1.9 christos { 0, 0 }
141 1.1 christos };
142 1.1 christos
143 1.1.1.9 christos static struct tui_translate tui_border_kind_translate_corner[] = {
144 1.1 christos { "space", ' ' },
145 1.1 christos { "ascii", '+' },
146 1.1.1.9 christos { 0, 0 }
147 1.1 christos };
148 1.1 christos
149 1.1 christos
150 1.1 christos /* Tui configuration variables controlled with set/show command. */
151 1.1.1.7 christos static const char *tui_active_border_mode = "bold-standout";
152 1.1 christos static void
153 1.1 christos show_tui_active_border_mode (struct ui_file *file,
154 1.1 christos int from_tty,
155 1.1 christos struct cmd_list_element *c,
156 1.1 christos const char *value)
157 1.1 christos {
158 1.1.1.8 christos gdb_printf (file, _("\
159 1.1 christos The attribute mode to use for the active TUI window border is \"%s\".\n"),
160 1.1.1.8 christos value);
161 1.1 christos }
162 1.1 christos
163 1.1.1.7 christos static const char *tui_border_mode = "normal";
164 1.1 christos static void
165 1.1 christos show_tui_border_mode (struct ui_file *file,
166 1.1 christos int from_tty,
167 1.1 christos struct cmd_list_element *c,
168 1.1 christos const char *value)
169 1.1 christos {
170 1.1.1.8 christos gdb_printf (file, _("\
171 1.1 christos The attribute mode to use for the TUI window borders is \"%s\".\n"),
172 1.1.1.8 christos value);
173 1.1 christos }
174 1.1 christos
175 1.1.1.7 christos static const char *tui_border_kind = "acs";
176 1.1 christos static void
177 1.1 christos show_tui_border_kind (struct ui_file *file,
178 1.1 christos int from_tty,
179 1.1 christos struct cmd_list_element *c,
180 1.1 christos const char *value)
181 1.1 christos {
182 1.1.1.8 christos gdb_printf (file, _("The kind of border for TUI windows is \"%s\".\n"),
183 1.1.1.8 christos value);
184 1.1.1.8 christos }
185 1.1.1.8 christos
186 1.1.1.8 christos /* Implementation of the "set/show style tui-current-position" commands. */
187 1.1.1.8 christos
188 1.1.1.8 christos bool style_tui_current_position = false;
189 1.1.1.8 christos
190 1.1.1.8 christos static void
191 1.1.1.8 christos show_style_tui_current_position (ui_file *file,
192 1.1.1.8 christos int from_tty,
193 1.1.1.8 christos cmd_list_element *c,
194 1.1.1.8 christos const char *value)
195 1.1.1.8 christos {
196 1.1.1.8 christos gdb_printf (file, _("\
197 1.1.1.8 christos Styling the text highlighted by the TUI's current position indicator is %s.\n"),
198 1.1 christos value);
199 1.1 christos }
200 1.1 christos
201 1.1.1.8 christos static void
202 1.1.1.8 christos set_style_tui_current_position (const char *ignore, int from_tty,
203 1.1.1.8 christos cmd_list_element *c)
204 1.1.1.8 christos {
205 1.1.1.8 christos if (TUI_SRC_WIN != nullptr)
206 1.1.1.8 christos TUI_SRC_WIN->refill ();
207 1.1.1.8 christos if (TUI_DISASM_WIN != nullptr)
208 1.1.1.8 christos TUI_DISASM_WIN->refill ();
209 1.1.1.8 christos }
210 1.1 christos
211 1.1 christos /* Tui internal configuration variables. These variables are updated
212 1.1 christos by tui_update_variables to reflect the tui configuration
213 1.1 christos variables. */
214 1.1 christos chtype tui_border_vline;
215 1.1 christos chtype tui_border_hline;
216 1.1 christos chtype tui_border_ulcorner;
217 1.1 christos chtype tui_border_urcorner;
218 1.1 christos chtype tui_border_llcorner;
219 1.1 christos chtype tui_border_lrcorner;
220 1.1 christos
221 1.1 christos int tui_border_attrs;
222 1.1 christos int tui_active_border_attrs;
223 1.1 christos
224 1.1.1.9 christos /* Identify the item in the translation table, and return the corresponding value. */
225 1.1.1.9 christos static int
226 1.1 christos translate (const char *name, struct tui_translate *table)
227 1.1 christos {
228 1.1 christos while (table->name)
229 1.1 christos {
230 1.1 christos if (name && strcmp (table->name, name) == 0)
231 1.1.1.9 christos return table->value;
232 1.1 christos table++;
233 1.1 christos }
234 1.1 christos
235 1.1.1.9 christos gdb_assert_not_reached ("");
236 1.1.1.9 christos }
237 1.1.1.9 christos
238 1.1.1.9 christos /* Translate NAME to a value. If NAME is "acs", use ACS_CHAR. Otherwise, use
239 1.1.1.9 christos translation table TABLE. */
240 1.1.1.9 christos static int
241 1.1.1.9 christos translate_acs (const char *name, struct tui_translate *table, int acs_char)
242 1.1.1.9 christos {
243 1.1.1.9 christos /* The ACS characters are determined at run time by curses terminal
244 1.1.1.9 christos management. */
245 1.1.1.9 christos if (strcmp (name, "acs") == 0)
246 1.1.1.9 christos return acs_char;
247 1.1.1.9 christos
248 1.1.1.9 christos return translate (name, table);
249 1.1 christos }
250 1.1 christos
251 1.1 christos /* Update the tui internal configuration according to gdb settings.
252 1.1 christos Returns 1 if the configuration has changed and the screen should
253 1.1 christos be redrawn. */
254 1.1.1.7 christos bool
255 1.1.1.7 christos tui_update_variables ()
256 1.1 christos {
257 1.1.1.7 christos bool need_redraw = false;
258 1.1.1.9 christos int val;
259 1.1 christos
260 1.1.1.9 christos val = translate (tui_border_mode, tui_border_mode_translate);
261 1.1.1.9 christos need_redraw |= assign_return_if_changed<int> (tui_border_attrs, val);
262 1.1 christos
263 1.1.1.9 christos val = translate (tui_active_border_mode, tui_border_mode_translate);
264 1.1.1.9 christos need_redraw |= assign_return_if_changed<int> (tui_active_border_attrs, val);
265 1.1 christos
266 1.1.1.9 christos /* If one corner changes, all characters are changed. Only check the first
267 1.1.1.9 christos one. */
268 1.1.1.9 christos val = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
269 1.1.1.9 christos ACS_LRCORNER);
270 1.1.1.9 christos need_redraw |= assign_return_if_changed<chtype> (tui_border_lrcorner, val);
271 1.1.1.9 christos
272 1.1.1.9 christos tui_border_llcorner
273 1.1.1.9 christos = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
274 1.1.1.9 christos ACS_LLCORNER);
275 1.1.1.9 christos
276 1.1.1.9 christos tui_border_ulcorner
277 1.1.1.9 christos = translate_acs (tui_border_kind, tui_border_kind_translate_corner,
278 1.1.1.9 christos ACS_ULCORNER);
279 1.1.1.9 christos
280 1.1.1.9 christos tui_border_urcorner =
281 1.1.1.9 christos translate_acs (tui_border_kind, tui_border_kind_translate_corner,
282 1.1.1.9 christos ACS_URCORNER);
283 1.1.1.9 christos
284 1.1.1.9 christos tui_border_hline
285 1.1.1.9 christos = translate_acs (tui_border_kind, tui_border_kind_translate_hline,
286 1.1.1.9 christos ACS_HLINE);
287 1.1.1.9 christos
288 1.1.1.9 christos tui_border_vline
289 1.1.1.9 christos = translate_acs (tui_border_kind, tui_border_kind_translate_vline,
290 1.1.1.9 christos ACS_VLINE);
291 1.1 christos
292 1.1 christos return need_redraw;
293 1.1 christos }
294 1.1 christos
295 1.1 christos static struct cmd_list_element *tuilist;
296 1.1 christos
297 1.1 christos struct cmd_list_element **
298 1.1 christos tui_get_cmd_list (void)
299 1.1 christos {
300 1.1 christos if (tuilist == 0)
301 1.1.1.7 christos add_basic_prefix_cmd ("tui", class_tui,
302 1.1.1.7 christos _("Text User Interface commands."),
303 1.1.1.8 christos &tuilist, 0, &cmdlist);
304 1.1 christos return &tuilist;
305 1.1 christos }
306 1.1 christos
307 1.1.1.2 christos /* The set_func hook of "set tui ..." commands that affect the window
308 1.1.1.2 christos borders on the TUI display. */
309 1.1.1.7 christos
310 1.1.1.7 christos static void
311 1.1.1.6 christos tui_set_var_cmd (const char *null_args,
312 1.1.1.6 christos int from_tty, struct cmd_list_element *c)
313 1.1.1.2 christos {
314 1.1.1.2 christos if (tui_update_variables () && tui_active)
315 1.1.1.2 christos tui_rehighlight_all ();
316 1.1.1.2 christos }
317 1.1.1.2 christos
318 1.1.1.7 christos
319 1.1.1.7 christos
321 1.1.1.7 christos /* True if TUI resizes should print a message. This is used by the
322 1.1.1.7 christos test suite. */
323 1.1.1.7 christos
324 1.1.1.7 christos static bool resize_message;
325 1.1.1.7 christos
326 1.1.1.7 christos static void
327 1.1.1.7 christos show_tui_resize_message (struct ui_file *file, int from_tty,
328 1.1.1.7 christos struct cmd_list_element *c, const char *value)
329 1.1.1.8 christos {
330 1.1.1.7 christos gdb_printf (file, _("TUI resize messaging is %s.\n"), value);
331 1.1.1.7 christos }
332 1.1.1.7 christos
333 1.1.1.7 christos
334 1.1.1.4 christos
336 1.1.1.9 christos /* Generic window name completion function. Complete window name pointed
337 1.1.1.9 christos to by TEXT and WORD.
338 1.1.1.9 christos
339 1.1.1.9 christos If EXCLUDE_CANNOT_FOCUS_P is true, then windows that can't take focus
340 1.1.1.9 christos will be excluded from the completions, otherwise they will be included.
341 1.1.1.9 christos
342 1.1.1.9 christos If INCLUDE_NEXT_PREV_P is true then the special window names 'next' and
343 1.1.1.3 christos 'prev' will also be considered as possible completions of the window
344 1.1.1.6 christos name. This is independent of EXCLUDE_CANNOT_FOCUS_P. */
345 1.1.1.6 christos
346 1.1.1.9 christos static void
347 1.1.1.9 christos window_name_completer (completion_tracker &tracker,
348 1.1.1.4 christos bool include_next_prev_p,
349 1.1.1.3 christos bool exclude_cannot_focus_p,
350 1.1.1.6 christos const char *text, const char *word)
351 1.1.1.3 christos {
352 1.1.1.7 christos std::vector<const char *> completion_name_vec;
353 1.1.1.3 christos
354 1.1.1.3 christos for (tui_win_info *win_info : all_tui_windows ())
355 1.1.1.3 christos {
356 1.1.1.9 christos const char *completion_name = NULL;
357 1.1.1.7 christos
358 1.1.1.3 christos /* Don't include an invisible window. */
359 1.1.1.3 christos if (!win_info->is_visible ())
360 1.1.1.9 christos continue;
361 1.1.1.9 christos
362 1.1.1.9 christos /* If requested, exclude windows that can't be focused. */
363 1.1.1.9 christos if (exclude_cannot_focus_p && !win_info->can_focus ())
364 1.1.1.7 christos continue;
365 1.1.1.4 christos
366 1.1.1.6 christos completion_name = win_info->name ();
367 1.1.1.3 christos gdb_assert (completion_name != NULL);
368 1.1.1.3 christos completion_name_vec.push_back (completion_name);
369 1.1.1.3 christos }
370 1.1.1.3 christos
371 1.1.1.3 christos /* If no windows are considered visible then the TUI has not yet been
372 1.1.1.7 christos initialized. But still "focus src" and "focus cmd" will work because
373 1.1.1.6 christos invoking the focus command will entail initializing the TUI which sets the
374 1.1.1.3 christos default layout to "src". */
375 1.1.1.6 christos if (completion_name_vec.empty ())
376 1.1.1.6 christos {
377 1.1.1.3 christos completion_name_vec.push_back (SRC_NAME);
378 1.1.1.3 christos completion_name_vec.push_back (CMD_NAME);
379 1.1.1.4 christos }
380 1.1.1.4 christos
381 1.1.1.6 christos if (include_next_prev_p)
382 1.1.1.6 christos {
383 1.1.1.4 christos completion_name_vec.push_back ("next");
384 1.1.1.3 christos completion_name_vec.push_back ("prev");
385 1.1.1.3 christos }
386 1.1.1.6 christos
387 1.1.1.6 christos
388 1.1.1.3 christos completion_name_vec.push_back (NULL);
389 1.1.1.3 christos complete_on_enum (tracker, completion_name_vec.data (), text, word);
390 1.1.1.4 christos }
391 1.1.1.4 christos
392 1.1.1.4 christos /* Complete possible window names to focus on. TEXT is the complete text
393 1.1.1.6 christos entered so far, WORD is the word currently being completed. */
394 1.1.1.4 christos
395 1.1.1.6 christos static void
396 1.1.1.6 christos focus_completer (struct cmd_list_element *ignore,
397 1.1.1.4 christos completion_tracker &tracker,
398 1.1.1.9 christos const char *text, const char *word)
399 1.1.1.4 christos {
400 1.1.1.4 christos window_name_completer (tracker, true, true, text, word);
401 1.1.1.4 christos }
402 1.1.1.4 christos
403 1.1.1.4 christos /* Complete possible window names for winheight command. TEXT is the
404 1.1.1.4 christos complete text entered so far, WORD is the word currently being
405 1.1.1.6 christos completed. */
406 1.1.1.4 christos
407 1.1.1.6 christos static void
408 1.1.1.4 christos winheight_completer (struct cmd_list_element *ignore,
409 1.1.1.4 christos completion_tracker &tracker,
410 1.1.1.4 christos const char *text, const char *word)
411 1.1.1.4 christos {
412 1.1.1.4 christos /* The first word is the window name. That we can complete. Subsequent
413 1.1.1.6 christos words can't be completed. */
414 1.1.1.4 christos if (word != text)
415 1.1.1.9 christos return;
416 1.1 christos
417 1.1 christos window_name_completer (tracker, false, false, text, word);
418 1.1 christos }
419 1.1 christos
420 1.1 christos /* Update gdb's knowledge of the terminal size. */
421 1.1 christos void
422 1.1.1.3 christos tui_update_gdb_sizes (void)
423 1.1 christos {
424 1.1.1.3 christos int width, height;
425 1.1.1.3 christos
426 1.1.1.7 christos if (tui_active)
427 1.1.1.7 christos {
428 1.1.1.3 christos width = TUI_CMD_WIN->width;
429 1.1.1.3 christos height = TUI_CMD_WIN->height;
430 1.1.1.3 christos }
431 1.1.1.3 christos else
432 1.1.1.3 christos {
433 1.1.1.3 christos width = tui_term_width ();
434 1.1.1.3 christos height = tui_term_height ();
435 1.1.1.3 christos }
436 1.1 christos
437 1.1 christos set_screen_width_and_height (width, height);
438 1.1 christos }
439 1.1 christos
440 1.1.1.7 christos
441 1.1 christos void
442 1.1.1.7 christos tui_win_info::forward_scroll (int num_to_scroll)
443 1.1.1.7 christos {
444 1.1 christos if (num_to_scroll == 0)
445 1.1.1.7 christos num_to_scroll = height - 3;
446 1.1 christos
447 1.1 christos do_scroll_vertical (num_to_scroll);
448 1.1 christos }
449 1.1.1.7 christos
450 1.1 christos void
451 1.1.1.7 christos tui_win_info::backward_scroll (int num_to_scroll)
452 1.1.1.7 christos {
453 1.1 christos if (num_to_scroll == 0)
454 1.1.1.7 christos num_to_scroll = height - 3;
455 1.1 christos
456 1.1 christos do_scroll_vertical (-num_to_scroll);
457 1.1 christos }
458 1.1 christos
459 1.1.1.7 christos
460 1.1 christos void
461 1.1.1.7 christos tui_win_info::left_scroll (int num_to_scroll)
462 1.1.1.7 christos {
463 1.1 christos if (num_to_scroll == 0)
464 1.1.1.7 christos num_to_scroll = 1;
465 1.1 christos
466 1.1 christos do_scroll_horizontal (num_to_scroll);
467 1.1 christos }
468 1.1 christos
469 1.1.1.7 christos
470 1.1 christos void
471 1.1.1.7 christos tui_win_info::right_scroll (int num_to_scroll)
472 1.1.1.7 christos {
473 1.1 christos if (num_to_scroll == 0)
474 1.1.1.7 christos num_to_scroll = 1;
475 1.1 christos
476 1.1 christos do_scroll_horizontal (-num_to_scroll);
477 1.1 christos }
478 1.1 christos
479 1.1 christos
480 1.1 christos void
481 1.1 christos tui_refresh_all_win (void)
482 1.1.1.9 christos {
483 1.1.1.9 christos clearok (curscr, TRUE);
484 1.1.1.9 christos for (tui_win_info *win_info : all_tui_windows ())
485 1.1.1.9 christos {
486 1.1.1.9 christos if (win_info->is_visible ())
487 1.1 christos win_info->refresh_window ();
488 1.1 christos }
489 1.1.1.2 christos }
490 1.1.1.2 christos
491 1.1.1.2 christos void
492 1.1.1.7 christos tui_rehighlight_all (void)
493 1.1.1.7 christos {
494 1.1.1.2 christos for (tui_win_info *win_info : all_tui_windows ())
495 1.1 christos win_info->check_and_display_highlight_if_needed ();
496 1.1 christos }
497 1.1.1.7 christos
498 1.1 christos /* Resize all the windows based on the terminal size. This function
499 1.1 christos gets called from within the readline SIGWINCH handler. */
500 1.1 christos void
501 1.1 christos tui_resize_all (void)
502 1.1 christos {
503 1.1 christos int height_diff, width_diff;
504 1.1 christos int screenheight, screenwidth;
505 1.1.1.9 christos
506 1.1.1.9 christos rl_get_screen_size (&screenheight, &screenwidth);
507 1.1 christos screenwidth += readline_hidden_cols;
508 1.1 christos
509 1.1 christos width_diff = screenwidth - tui_term_width ();
510 1.1 christos height_diff = screenheight - tui_term_height ();
511 1.1 christos if (height_diff || width_diff)
512 1.1 christos {
513 1.1 christos #ifdef HAVE_RESIZE_TERM
514 1.1 christos resize_term (screenheight, screenwidth);
515 1.1.1.8 christos #endif
516 1.1 christos /* Turn keypad off while we resize. */
517 1.1 christos keypad (TUI_CMD_WIN->handle.get (), FALSE);
518 1.1 christos tui_update_gdb_sizes ();
519 1.1.1.7 christos tui_set_term_height_to (screenheight);
520 1.1 christos tui_set_term_width_to (screenwidth);
521 1.1.1.8 christos
522 1.1 christos /* erase + clearok are used instead of a straightforward clear as
523 1.1 christos AIX 5.3 does not define clear. */
524 1.1.1.8 christos erase ();
525 1.1.1.8 christos clearok (curscr, TRUE);
526 1.1.1.8 christos /* Apply the current layout. The 'false' here allows the command
527 1.1.1.8 christos window to resize proportionately with containing terminal, rather
528 1.1.1.8 christos than maintaining a fixed size. */
529 1.1 christos tui_apply_current_layout (false); /* Turn keypad back on. */
530 1.1 christos keypad (TUI_CMD_WIN->handle.get (), TRUE);
531 1.1 christos }
532 1.1 christos }
533 1.1.1.3 christos
534 1.1.1.3 christos #ifdef SIGWINCH
535 1.1.1.3 christos /* Token for use by TUI's asynchronous SIGWINCH handler. */
536 1.1.1.3 christos static struct async_signal_handler *tui_sigwinch_token;
537 1.1 christos
538 1.1 christos /* TUI's SIGWINCH signal handler. */
539 1.1 christos static void
540 1.1.1.3 christos tui_sigwinch_handler (int signal)
541 1.1.1.7 christos {
542 1.1 christos mark_async_signal_handler (tui_sigwinch_token);
543 1.1.1.3 christos tui_set_win_resized_to (true);
544 1.1.1.3 christos }
545 1.1.1.3 christos
546 1.1.1.3 christos /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
547 1.1.1.3 christos static void
548 1.1.1.3 christos tui_async_resize_screen (gdb_client_data arg)
549 1.1.1.3 christos {
550 1.1.1.3 christos rl_resize_terminal ();
551 1.1.1.3 christos
552 1.1.1.3 christos if (!tui_active)
553 1.1.1.3 christos {
554 1.1.1.3 christos int screen_height, screen_width;
555 1.1.1.9 christos
556 1.1.1.3 christos rl_get_screen_size (&screen_height, &screen_width);
557 1.1.1.3 christos screen_width += readline_hidden_cols;
558 1.1.1.3 christos set_screen_width_and_height (screen_width, screen_height);
559 1.1.1.3 christos
560 1.1.1.3 christos /* win_resized is left set so that the next call to tui_enable()
561 1.1.1.3 christos resizes the TUI windows. */
562 1.1.1.3 christos }
563 1.1.1.7 christos else
564 1.1.1.3 christos {
565 1.1.1.3 christos tui_set_win_resized_to (false);
566 1.1.1.3 christos tui_resize_all ();
567 1.1.1.7 christos tui_refresh_all_win ();
568 1.1.1.7 christos tui_update_gdb_sizes ();
569 1.1.1.7 christos if (resize_message)
570 1.1.1.7 christos {
571 1.1.1.7 christos static int count;
572 1.1.1.7 christos printf_unfiltered ("@@ resize done %d, size = %dx%d\n", count,
573 1.1.1.7 christos tui_term_width (), tui_term_height ());
574 1.1.1.3 christos ++count;
575 1.1.1.3 christos }
576 1.1.1.3 christos tui_redisplay_readline ();
577 1.1 christos }
578 1.1 christos }
579 1.1.1.3 christos #endif
580 1.1.1.3 christos
581 1.1.1.3 christos /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
582 1.1 christos uninstalled when we exit TUI, so the handler should not assume that TUI is
583 1.1 christos always active. */
584 1.1 christos void
585 1.1 christos tui_initialize_win (void)
586 1.1.1.3 christos {
587 1.1.1.8 christos #ifdef SIGWINCH
588 1.1.1.8 christos tui_sigwinch_token
589 1.1.1.3 christos = create_async_signal_handler (tui_async_resize_screen, NULL,
590 1.1.1.3 christos "tui-sigwinch");
591 1.1 christos
592 1.1.1.3 christos {
593 1.1 christos #ifdef HAVE_SIGACTION
594 1.1.1.3 christos struct sigaction old_winch;
595 1.1.1.3 christos
596 1.1.1.2 christos memset (&old_winch, 0, sizeof (old_winch));
597 1.1.1.3 christos old_winch.sa_handler = &tui_sigwinch_handler;
598 1.1.1.2 christos #ifdef SA_RESTART
599 1.1.1.3 christos old_winch.sa_flags = SA_RESTART;
600 1.1 christos #endif
601 1.1.1.3 christos sigaction (SIGWINCH, &old_winch, NULL);
602 1.1 christos #else
603 1.1.1.3 christos signal (SIGWINCH, &tui_sigwinch_handler);
604 1.1 christos #endif
605 1.1 christos }
606 1.1 christos #endif
607 1.1 christos }
608 1.1 christos
609 1.1.1.6 christos
610 1.1 christos static void
611 1.1 christos tui_scroll_forward_command (const char *arg, int from_tty)
612 1.1 christos {
613 1.1 christos int num_to_scroll = 1;
614 1.1 christos struct tui_win_info *win_to_scroll;
615 1.1 christos
616 1.1.1.6 christos /* Make sure the curses mode is enabled. */
617 1.1.1.7 christos tui_enable ();
618 1.1 christos if (arg == NULL)
619 1.1 christos parse_scrolling_args (arg, &win_to_scroll, NULL);
620 1.1.1.7 christos else
621 1.1 christos parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
622 1.1 christos win_to_scroll->forward_scroll (num_to_scroll);
623 1.1 christos }
624 1.1 christos
625 1.1.1.6 christos
626 1.1 christos static void
627 1.1 christos tui_scroll_backward_command (const char *arg, int from_tty)
628 1.1 christos {
629 1.1 christos int num_to_scroll = 1;
630 1.1 christos struct tui_win_info *win_to_scroll;
631 1.1 christos
632 1.1.1.6 christos /* Make sure the curses mode is enabled. */
633 1.1.1.7 christos tui_enable ();
634 1.1 christos if (arg == NULL)
635 1.1 christos parse_scrolling_args (arg, &win_to_scroll, NULL);
636 1.1.1.7 christos else
637 1.1 christos parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
638 1.1 christos win_to_scroll->backward_scroll (num_to_scroll);
639 1.1 christos }
640 1.1 christos
641 1.1.1.6 christos
642 1.1 christos static void
643 1.1 christos tui_scroll_left_command (const char *arg, int from_tty)
644 1.1 christos {
645 1.1 christos int num_to_scroll;
646 1.1 christos struct tui_win_info *win_to_scroll;
647 1.1 christos
648 1.1 christos /* Make sure the curses mode is enabled. */
649 1.1.1.7 christos tui_enable ();
650 1.1 christos parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
651 1.1 christos win_to_scroll->left_scroll (num_to_scroll);
652 1.1 christos }
653 1.1 christos
654 1.1.1.6 christos
655 1.1 christos static void
656 1.1 christos tui_scroll_right_command (const char *arg, int from_tty)
657 1.1 christos {
658 1.1 christos int num_to_scroll;
659 1.1 christos struct tui_win_info *win_to_scroll;
660 1.1 christos
661 1.1 christos /* Make sure the curses mode is enabled. */
662 1.1.1.7 christos tui_enable ();
663 1.1 christos parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
664 1.1 christos win_to_scroll->right_scroll (num_to_scroll);
665 1.1 christos }
666 1.1.1.7 christos
667 1.1.1.7 christos
668 1.1.1.9 christos /* Answer the window represented by name. */
669 1.1 christos static struct tui_win_info *
670 1.1.1.7 christos tui_partial_win_by_name (std::string_view name)
671 1.1.1.7 christos {
672 1.1.1.7 christos struct tui_win_info *best = nullptr;
673 1.1 christos
674 1.1.1.7 christos for (tui_win_info *item : all_tui_windows ())
675 1.1 christos {
676 1.1.1.7 christos const char *cur_name = item->name ();
677 1.1.1.7 christos
678 1.1.1.7 christos if (name == cur_name)
679 1.1 christos return item;
680 1.1.1.7 christos if (startswith (cur_name, name))
681 1.1.1.7 christos {
682 1.1.1.7 christos if (best != nullptr)
683 1.1.1.7 christos error (_("Window name \"%*s\" is ambiguous"),
684 1.1 christos (int) name.size (), name.data ());
685 1.1 christos best = item;
686 1.1.1.7 christos }
687 1.1.1.7 christos }
688 1.1 christos
689 1.1 christos return best;
690 1.1.1.7 christos }
691 1.1 christos
692 1.1.1.6 christos /* Set focus to the window named by 'arg'. */
693 1.1 christos static void
694 1.1 christos tui_set_focus_command (const char *arg, int from_tty)
695 1.1 christos {
696 1.1.1.7 christos tui_enable ();
697 1.1.1.7 christos
698 1.1.1.7 christos if (arg == NULL)
699 1.1.1.7 christos error_no_arg (_("name of window to focus"));
700 1.1.1.7 christos
701 1.1.1.8 christos struct tui_win_info *win_info = NULL;
702 1.1.1.7 christos
703 1.1.1.8 christos if (startswith ("next", arg))
704 1.1.1.7 christos win_info = tui_next_win (tui_win_with_focus ());
705 1.1.1.7 christos else if (startswith ("prev", arg))
706 1.1.1.7 christos win_info = tui_prev_win (tui_win_with_focus ());
707 1.1.1.7 christos else
708 1.1.1.9 christos win_info = tui_partial_win_by_name (arg);
709 1.1.1.9 christos
710 1.1.1.9 christos if (win_info == nullptr)
711 1.1.1.9 christos {
712 1.1.1.9 christos /* When WIN_INFO is nullptr this can either mean that the window name
713 1.1.1.9 christos is unknown to GDB, or that the window is not in the current
714 1.1.1.9 christos layout. To try and help the user, give a different error
715 1.1.1.9 christos depending on which of these is the case. */
716 1.1.1.9 christos std::string matching_window_name;
717 1.1.1.9 christos bool is_ambiguous = false;
718 1.1.1.9 christos
719 1.1.1.9 christos for (const std::string &name : all_known_window_names ())
720 1.1.1.9 christos {
721 1.1.1.9 christos /* Look through all windows in the current layout, if the window
722 1.1.1.9 christos is in the current layout then we're not interested is it. */
723 1.1.1.9 christos for (tui_win_info *item : all_tui_windows ())
724 1.1.1.9 christos if (item->name () == name)
725 1.1.1.9 christos continue;
726 1.1.1.9 christos
727 1.1.1.9 christos if (startswith (name, arg))
728 1.1.1.9 christos {
729 1.1.1.9 christos if (matching_window_name.empty ())
730 1.1.1.9 christos matching_window_name = name;
731 1.1.1.9 christos else
732 1.1.1.9 christos is_ambiguous = true;
733 1.1.1.9 christos }
734 1.1.1.9 christos };
735 1.1.1.9 christos
736 1.1.1.9 christos if (!matching_window_name.empty ())
737 1.1.1.9 christos {
738 1.1.1.9 christos if (is_ambiguous)
739 1.1.1.9 christos error (_("No windows matching \"%s\" in the current layout"),
740 1.1.1.9 christos arg);
741 1.1.1.9 christos else
742 1.1.1.9 christos error (_("Window \"%s\" is not in the current layout"),
743 1.1.1.9 christos matching_window_name.c_str ());
744 1.1.1.9 christos }
745 1.1.1.9 christos else
746 1.1.1.9 christos error (_("Unrecognized window name \"%s\""), arg);
747 1.1.1.9 christos }
748 1.1.1.9 christos
749 1.1.1.9 christos /* If a window is part of the current layout then it will have a
750 1.1.1.9 christos tui_win_info associated with it and be visible, otherwise, there will
751 1.1.1.9 christos be no tui_win_info and the above error will have been raised. */
752 1.1.1.9 christos gdb_assert (win_info->is_visible ());
753 1.1.1.9 christos
754 1.1.1.7 christos if (!win_info->can_focus ())
755 1.1.1.7 christos error (_("Window \"%s\" cannot be focused"), arg);
756 1.1.1.8 christos
757 1.1.1.8 christos tui_set_win_focus_to (win_info);
758 1.1.1.7 christos gdb_printf (_("Focus set to %s window.\n"),
759 1.1 christos tui_win_with_focus ()->name ());
760 1.1 christos }
761 1.1.1.6 christos
762 1.1 christos static void
763 1.1.1.7 christos tui_all_windows_info (const char *arg, int from_tty)
764 1.1.1.7 christos {
765 1.1.1.8 christos if (!tui_active)
766 1.1.1.7 christos {
767 1.1.1.7 christos gdb_printf (_("The TUI is not active.\n"));
768 1.1.1.7 christos return;
769 1.1 christos }
770 1.1.1.7 christos
771 1.1.1.7 christos struct tui_win_info *win_with_focus = tui_win_with_focus ();
772 1.1.1.8 christos struct ui_out *uiout = current_uiout;
773 1.1.1.7 christos
774 1.1.1.7 christos ui_out_emit_table table_emitter (uiout, 4, -1, "tui-windows");
775 1.1.1.8 christos uiout->table_header (10, ui_left, "name", "Name");
776 1.1.1.7 christos uiout->table_header (5, ui_right, "lines", "Lines");
777 1.1.1.7 christos uiout->table_header (7, ui_right, "columns", "Columns");
778 1.1 christos uiout->table_header (10, ui_left, "focus", "Focus");
779 1.1.1.7 christos uiout->table_body ();
780 1.1.1.7 christos
781 1.1 christos for (tui_win_info *win_info : all_tui_windows ())
782 1.1.1.7 christos if (win_info->is_visible ())
783 1.1.1.7 christos {
784 1.1.1.7 christos ui_out_emit_tuple tuple_emitter (uiout, nullptr);
785 1.1.1.7 christos
786 1.1.1.8 christos uiout->field_string ("name", win_info->name ());
787 1.1.1.7 christos uiout->field_signed ("lines", win_info->height);
788 1.1.1.7 christos uiout->field_signed ("columns", win_info->width);
789 1.1 christos if (win_with_focus == win_info)
790 1.1.1.7 christos uiout->field_string ("focus", _("(has focus)"));
791 1.1.1.7 christos else
792 1.1 christos uiout->field_skip ("focus");
793 1.1 christos uiout->text ("\n");
794 1.1 christos }
795 1.1 christos }
796 1.1 christos
797 1.1.1.6 christos
798 1.1 christos static void
799 1.1 christos tui_refresh_all_command (const char *arg, int from_tty)
800 1.1 christos {
801 1.1 christos /* Make sure the curses mode is enabled. */
802 1.1 christos tui_enable ();
803 1.1 christos
804 1.1 christos tui_refresh_all_win ();
805 1.1.1.7 christos }
806 1.1.1.7 christos
807 1.1.1.6 christos #define DEFAULT_TAB_LEN 8
808 1.1.1.6 christos
809 1.1.1.6 christos /* The tab width that should be used by the TUI. */
810 1.1.1.6 christos
811 1.1.1.6 christos unsigned int tui_tab_width = DEFAULT_TAB_LEN;
812 1.1.1.6 christos
813 1.1.1.6 christos /* The tab width as set by the user. */
814 1.1.1.6 christos
815 1.1.1.6 christos static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
816 1.1.1.6 christos
817 1.1.1.6 christos /* After the tab width is set, call this to update the relevant
818 1.1.1.6 christos windows. */
819 1.1.1.6 christos
820 1.1.1.6 christos static void
821 1.1.1.7 christos update_tab_width ()
822 1.1.1.6 christos {
823 1.1.1.7 christos for (tui_win_info *win_info : all_tui_windows ())
824 1.1.1.7 christos {
825 1.1.1.6 christos if (win_info->is_visible ())
826 1.1.1.6 christos win_info->update_tab_width ();
827 1.1.1.6 christos }
828 1.1.1.6 christos }
829 1.1.1.6 christos
830 1.1.1.6 christos /* Callback for "set tui tab-width". */
831 1.1.1.6 christos
832 1.1.1.6 christos static void
833 1.1.1.6 christos tui_set_tab_width (const char *ignore,
834 1.1.1.6 christos int from_tty, struct cmd_list_element *c)
835 1.1.1.6 christos {
836 1.1.1.6 christos if (internal_tab_width == 0)
837 1.1.1.6 christos {
838 1.1.1.6 christos internal_tab_width = tui_tab_width;
839 1.1.1.6 christos error (_("Tab width must not be 0"));
840 1.1.1.6 christos }
841 1.1.1.6 christos
842 1.1.1.6 christos tui_tab_width = internal_tab_width;
843 1.1.1.6 christos update_tab_width ();
844 1.1.1.6 christos }
845 1.1.1.6 christos
846 1.1.1.6 christos /* Callback for "show tui tab-width". */
847 1.1.1.6 christos
848 1.1.1.6 christos static void
849 1.1.1.6 christos tui_show_tab_width (struct ui_file *file, int from_tty,
850 1.1.1.8 christos struct cmd_list_element *c, const char *value)
851 1.1.1.6 christos {
852 1.1.1.6 christos gdb_printf (file, _("TUI tab width is %s spaces.\n"), value);
853 1.1 christos
854 1.1.1.7 christos }
855 1.1.1.7 christos
856 1.1.1.7 christos /* See tui-win.h. */
857 1.1.1.7 christos
858 1.1.1.7 christos bool compact_source = false;
859 1.1.1.7 christos
860 1.1.1.7 christos /* Callback for "set tui compact-source". */
861 1.1.1.7 christos
862 1.1.1.7 christos static void
863 1.1.1.7 christos tui_set_compact_source (const char *ignore, int from_tty,
864 1.1.1.7 christos struct cmd_list_element *c)
865 1.1.1.7 christos {
866 1.1.1.7 christos if (TUI_SRC_WIN != nullptr)
867 1.1.1.7 christos TUI_SRC_WIN->refill ();
868 1.1.1.7 christos }
869 1.1.1.7 christos
870 1.1.1.7 christos /* Callback for "show tui compact-source". */
871 1.1.1.7 christos
872 1.1.1.7 christos static void
873 1.1.1.7 christos tui_show_compact_source (struct ui_file *file, int from_tty,
874 1.1.1.8 christos struct cmd_list_element *c, const char *value)
875 1.1.1.7 christos {
876 1.1.1.7 christos gdb_printf (file, _("TUI source window compactness is %s.\n"), value);
877 1.1.1.9 christos }
878 1.1.1.9 christos
879 1.1.1.9 christos bool tui_enable_mouse = true;
880 1.1.1.9 christos
881 1.1.1.9 christos /* Implement 'show tui mouse-events'. */
882 1.1.1.9 christos
883 1.1.1.9 christos static void
884 1.1.1.9 christos show_tui_mouse_events (struct ui_file *file, int from_tty,
885 1.1.1.9 christos struct cmd_list_element *c, const char *value)
886 1.1.1.9 christos {
887 1.1.1.9 christos gdb_printf (file, _("TUI mouse events are %s.\n"), value);
888 1.1.1.3 christos }
889 1.1 christos
890 1.1.1.6 christos /* Set the tab width of the specified window. */
891 1.1 christos static void
892 1.1 christos tui_set_tab_width_command (const char *arg, int from_tty)
893 1.1 christos {
894 1.1.1.6 christos /* Make sure the curses mode is enabled. */
895 1.1 christos tui_enable ();
896 1.1 christos if (arg != NULL)
897 1.1 christos {
898 1.1 christos int ts;
899 1.1.1.6 christos
900 1.1.1.6 christos ts = atoi (arg);
901 1.1.1.6 christos if (ts <= 0)
902 1.1.1.2 christos warning (_("Tab widths greater than 0 must be specified."));
903 1.1.1.6 christos else
904 1.1.1.6 christos {
905 1.1.1.6 christos internal_tab_width = ts;
906 1.1.1.6 christos tui_tab_width = ts;
907 1.1.1.2 christos
908 1.1 christos update_tab_width ();
909 1.1 christos }
910 1.1 christos }
911 1.1.1.8 christos }
912 1.1.1.8 christos
913 1.1.1.8 christos /* Helper function for the user commands to adjust a window's width or
914 1.1.1.8 christos height. The ARG string contains the command line arguments from the
915 1.1.1.8 christos user, which should give the name of a window, and how to adjust the
916 1.1.1.8 christos size.
917 1.1.1.8 christos
918 1.1.1.8 christos When SET_WIDTH_P is true the width of the window is adjusted based on
919 1.1.1.8 christos ARG, and when SET_WIDTH_P is false, the height of the window is adjusted
920 1.1.1.8 christos based on ARG.
921 1.1.1.8 christos
922 1.1.1.8 christos On invalid input, or if the size can't be adjusted as requested, then an
923 1.1 christos error is thrown, otherwise, the window sizes are adjusted, and the
924 1.1 christos windows redrawn. */
925 1.1.1.8 christos
926 1.1 christos static void
927 1.1 christos tui_set_win_size (const char *arg, bool set_width_p)
928 1.1 christos {
929 1.1.1.7 christos /* Make sure the curses mode is enabled. */
930 1.1.1.7 christos tui_enable ();
931 1.1 christos if (arg == NULL)
932 1.1.1.7 christos error_no_arg (_("name of window"));
933 1.1.1.7 christos
934 1.1.1.8 christos const char *buf = arg;
935 1.1.1.7 christos const char *buf_ptr = buf;
936 1.1 christos int new_size;
937 1.1.1.7 christos struct tui_win_info *win_info;
938 1.1 christos
939 1.1.1.7 christos buf_ptr = skip_to_space (buf_ptr);
940 1.1.1.9 christos
941 1.1.1.7 christos /* Validate the window name. */
942 1.1 christos std::string_view wname (buf, buf_ptr - buf);
943 1.1.1.7 christos win_info = tui_partial_win_by_name (wname);
944 1.1.1.7 christos
945 1.1.1.7 christos if (win_info == NULL)
946 1.1.1.7 christos error (_("Unrecognized window name \"%s\""), arg);
947 1.1 christos if (!win_info->is_visible ())
948 1.1.1.7 christos error (_("Window \"%s\" is not visible"), arg);
949 1.1.1.7 christos
950 1.1 christos /* Process the size. */
951 1.1.1.7 christos buf_ptr = skip_spaces (buf_ptr);
952 1.1 christos
953 1.1.1.7 christos if (*buf_ptr != '\0')
954 1.1.1.7 christos {
955 1.1.1.7 christos bool negate = false;
956 1.1 christos bool fixed_size = true;
957 1.1.1.7 christos int input_no;;
958 1.1 christos
959 1.1.1.7 christos if (*buf_ptr == '+' || *buf_ptr == '-')
960 1.1.1.7 christos {
961 1.1.1.7 christos if (*buf_ptr == '-')
962 1.1.1.7 christos negate = true;
963 1.1 christos fixed_size = false;
964 1.1.1.7 christos buf_ptr++;
965 1.1.1.7 christos }
966 1.1 christos input_no = atoi (buf_ptr);
967 1.1.1.7 christos if (input_no > 0)
968 1.1.1.7 christos {
969 1.1.1.7 christos if (negate)
970 1.1.1.8 christos input_no *= (-1);
971 1.1.1.7 christos if (fixed_size)
972 1.1.1.8 christos new_size = input_no;
973 1.1.1.8 christos else
974 1.1.1.8 christos {
975 1.1.1.8 christos int curr_size;
976 1.1.1.8 christos if (set_width_p)
977 1.1.1.8 christos curr_size = win_info->width;
978 1.1.1.8 christos else
979 1.1.1.8 christos curr_size = win_info->height;
980 1.1.1.7 christos new_size = curr_size + input_no;
981 1.1.1.7 christos }
982 1.1.1.7 christos
983 1.1.1.8 christos /* Now change the window's height, and adjust
984 1.1.1.8 christos all other windows around it. */
985 1.1.1.8 christos if (set_width_p)
986 1.1.1.8 christos tui_adjust_window_width (win_info, new_size);
987 1.1.1.7 christos else
988 1.1 christos tui_adjust_window_height (win_info, new_size);
989 1.1.1.7 christos tui_update_gdb_sizes ();
990 1.1.1.8 christos }
991 1.1.1.8 christos else
992 1.1.1.8 christos {
993 1.1.1.8 christos if (set_width_p)
994 1.1.1.8 christos error (_("Invalid window width specified"));
995 1.1.1.8 christos else
996 1.1 christos error (_("Invalid window height specified"));
997 1.1 christos }
998 1.1 christos }
999 1.1.1.8 christos }
1000 1.1.1.8 christos
1001 1.1.1.8 christos /* Implement the 'tui window height' command (alias 'winheight'). */
1002 1.1.1.8 christos
1003 1.1.1.8 christos static void
1004 1.1.1.8 christos tui_set_win_height_command (const char *arg, int from_tty)
1005 1.1.1.8 christos {
1006 1.1.1.8 christos /* Pass false as the final argument to set the height. */
1007 1.1.1.8 christos tui_set_win_size (arg, false);
1008 1.1.1.8 christos }
1009 1.1.1.8 christos
1010 1.1.1.8 christos /* Implement the 'tui window width' command (alias 'winwidth'). */
1011 1.1.1.8 christos
1012 1.1.1.8 christos static void
1013 1.1.1.8 christos tui_set_win_width_command (const char *arg, int from_tty)
1014 1.1.1.8 christos {
1015 1.1.1.8 christos /* Pass true as the final argument to set the width. */
1016 1.1.1.8 christos tui_set_win_size (arg, true);
1017 1.1.1.7 christos }
1018 1.1 christos
1019 1.1.1.7 christos /* See tui-data.h. */
1020 1.1.1.7 christos
1021 1.1 christos int
1022 1.1.1.8 christos tui_win_info::max_height () const
1023 1.1 christos {
1024 1.1 christos return tui_term_height ();
1025 1.1.1.7 christos }
1026 1.1 christos
1027 1.1.1.7 christos /* See tui-data.h. */
1028 1.1.1.7 christos
1029 1.1 christos int
1030 1.1.1.8 christos tui_win_info::max_width () const
1031 1.1 christos {
1032 1.1 christos return tui_term_width ();
1033 1.1 christos }
1034 1.1.1.6 christos
1035 1.1 christos static void
1036 1.1 christos parse_scrolling_args (const char *arg,
1037 1.1 christos struct tui_win_info **win_to_scroll,
1038 1.1 christos int *num_to_scroll)
1039 1.1 christos {
1040 1.1 christos if (num_to_scroll)
1041 1.1 christos *num_to_scroll = 0;
1042 1.1 christos *win_to_scroll = tui_win_with_focus ();
1043 1.1 christos
1044 1.1.1.6 christos /* First set up the default window to scroll, in case there is no
1045 1.1 christos window name arg. */
1046 1.1.1.6 christos if (arg != NULL)
1047 1.1 christos {
1048 1.1 christos char *buf_ptr;
1049 1.1.1.6 christos
1050 1.1.1.6 christos /* Process the number of lines to scroll. */
1051 1.1 christos std::string copy = arg;
1052 1.1 christos buf_ptr = ©[0];
1053 1.1 christos if (isdigit (*buf_ptr))
1054 1.1 christos {
1055 1.1 christos char *num_str;
1056 1.1 christos
1057 1.1.1.6 christos num_str = buf_ptr;
1058 1.1 christos buf_ptr = strchr (buf_ptr, ' ');
1059 1.1.1.7 christos if (buf_ptr != NULL)
1060 1.1 christos {
1061 1.1 christos *buf_ptr = '\0';
1062 1.1 christos if (num_to_scroll)
1063 1.1 christos *num_to_scroll = atoi (num_str);
1064 1.1 christos buf_ptr++;
1065 1.1 christos }
1066 1.1 christos else if (num_to_scroll)
1067 1.1 christos *num_to_scroll = atoi (num_str);
1068 1.1 christos }
1069 1.1.1.6 christos
1070 1.1 christos /* Process the window name if one is specified. */
1071 1.1.1.5 christos if (buf_ptr != NULL)
1072 1.1 christos {
1073 1.1.1.7 christos const char *wname;
1074 1.1 christos
1075 1.1.1.7 christos wname = skip_spaces (buf_ptr);
1076 1.1 christos
1077 1.1.1.7 christos if (*wname != '\0')
1078 1.1.1.5 christos {
1079 1.1.1.7 christos *win_to_scroll = tui_partial_win_by_name (wname);
1080 1.1.1.7 christos
1081 1.1.1.7 christos if (*win_to_scroll == NULL)
1082 1.1.1.7 christos error (_("Unrecognized window `%s'"), wname);
1083 1.1.1.7 christos if (!(*win_to_scroll)->is_visible ())
1084 1.1.1.7 christos error (_("Window is not visible"));
1085 1.1 christos else if (*win_to_scroll == TUI_CMD_WIN)
1086 1.1 christos *win_to_scroll = *(tui_source_windows ().begin ());
1087 1.1 christos }
1088 1.1 christos }
1089 1.1.1.6 christos }
1090 1.1.1.8 christos }
1091 1.1.1.8 christos
1092 1.1.1.8 christos /* The list of 'tui window' sub-commands. */
1093 1.1.1.8 christos
1094 1.1.1.8 christos static cmd_list_element *tui_window_cmds = nullptr;
1095 1.1.1.8 christos
1096 1.1.1.8 christos /* Called to implement 'tui window'. */
1097 1.1.1.8 christos
1098 1.1.1.8 christos static void
1099 1.1.1.8 christos tui_window_command (const char *args, int from_tty)
1100 1.1.1.8 christos {
1101 1.1.1.8 christos help_list (tui_window_cmds, "tui window ", all_commands, gdb_stdout);
1102 1.1.1.9 christos }
1103 1.1.1.9 christos
1104 1.1.1.9 christos /* See tui-win.h. */
1105 1.1.1.9 christos
1106 1.1.1.6 christos bool tui_left_margin_verbose = false;
1107 1.1.1.6 christos
1108 1.1.1.6 christos /* Function to initialize gdb commands, for tui window
1109 1.1.1.7 christos manipulation. */
1110 1.1.1.6 christos
1111 1.1.1.7 christos void _initialize_tui_win ();
1112 1.1.1.6 christos void
1113 1.1.1.6 christos _initialize_tui_win ()
1114 1.1.1.6 christos {
1115 1.1.1.6 christos static struct cmd_list_element *tui_setlist;
1116 1.1.1.6 christos static struct cmd_list_element *tui_showlist;
1117 1.1.1.6 christos
1118 1.1.1.8 christos /* Define the classes of commands.
1119 1.1.1.8 christos They will appear in the help list in the reverse of this order. */
1120 1.1.1.8 christos add_setshow_prefix_cmd ("tui", class_tui,
1121 1.1.1.8 christos _("TUI configuration variables."),
1122 1.1.1.8 christos _("TUI configuration variables."),
1123 1.1.1.8 christos &tui_setlist, &tui_showlist,
1124 1.1.1.8 christos &setlist, &showlist);
1125 1.1.1.8 christos
1126 1.1.1.8 christos cmd_list_element *refresh_cmd
1127 1.1.1.8 christos = add_cmd ("refresh", class_tui, tui_refresh_all_command,
1128 1.1.1.8 christos _("Refresh the terminal display."),
1129 1.1.1.6 christos tui_get_cmd_list ());
1130 1.1.1.8 christos add_com_alias ("refresh", refresh_cmd, class_tui, 0);
1131 1.1.1.8 christos
1132 1.1.1.6 christos cmd_list_element *tabset_cmd
1133 1.1.1.7 christos = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1134 1.1.1.8 christos Set the width (in characters) of tab stops.\n\
1135 1.1.1.8 christos Usage: tabset N"));
1136 1.1.1.8 christos deprecate_cmd (tabset_cmd, "set tui tab-width");
1137 1.1.1.8 christos
1138 1.1.1.8 christos /* Setup the 'tui window' list of command. */
1139 1.1.1.8 christos add_prefix_cmd ("window", class_tui, tui_window_command,
1140 1.1.1.6 christos _("Text User Interface window commands."),
1141 1.1.1.8 christos &tui_window_cmds, 1, tui_get_cmd_list ());
1142 1.1.1.8 christos
1143 1.1.1.7 christos cmd_list_element *winheight_cmd
1144 1.1.1.8 christos = add_cmd ("height", class_tui, tui_set_win_height_command, _("\
1145 1.1.1.8 christos Set or modify the height of a specified window.\n\
1146 1.1.1.8 christos Usage: tui window height WINDOW-NAME [+ | -] NUM-LINES\n\
1147 1.1.1.8 christos Use \"info win\" to see the names of the windows currently being displayed."),
1148 1.1.1.8 christos &tui_window_cmds);
1149 1.1.1.8 christos add_com_alias ("winheight", winheight_cmd, class_tui, 0);
1150 1.1.1.8 christos add_com_alias ("wh", winheight_cmd, class_tui, 0);
1151 1.1.1.8 christos set_cmd_completer (winheight_cmd, winheight_completer);
1152 1.1.1.8 christos
1153 1.1.1.8 christos cmd_list_element *winwidth_cmd
1154 1.1.1.8 christos = add_cmd ("width", class_tui, tui_set_win_width_command, _("\
1155 1.1.1.8 christos Set or modify the width of a specified window.\n\
1156 1.1.1.8 christos Usage: tui window width WINDOW-NAME [+ | -] NUM-LINES\n\
1157 1.1.1.8 christos Use \"info win\" to see the names of the windows currently being displayed."),
1158 1.1.1.8 christos &tui_window_cmds);
1159 1.1.1.8 christos add_com_alias ("winwidth", winwidth_cmd, class_tui, 0);
1160 1.1.1.6 christos set_cmd_completer (winwidth_cmd, winheight_completer);
1161 1.1.1.7 christos
1162 1.1.1.7 christos add_info ("win", tui_all_windows_info,
1163 1.1.1.8 christos _("List of all displayed windows.\n\
1164 1.1.1.8 christos Usage: info win"));
1165 1.1.1.7 christos cmd_list_element *focus_cmd
1166 1.1.1.8 christos = add_cmd ("focus", class_tui, tui_set_focus_command, _("\
1167 1.1.1.8 christos Set focus to named window or next/prev window.\n\
1168 1.1.1.8 christos Usage: tui focus [WINDOW-NAME | next | prev]\n\
1169 1.1.1.8 christos Use \"info win\" to see the names of the windows currently being displayed."),
1170 1.1.1.8 christos tui_get_cmd_list ());
1171 1.1.1.8 christos add_com_alias ("focus", focus_cmd, class_tui, 0);
1172 1.1.1.6 christos add_com_alias ("fs", focus_cmd, class_tui, 0);
1173 1.1.1.6 christos set_cmd_completer (focus_cmd, focus_completer);
1174 1.1.1.7 christos add_com ("+", class_tui, tui_scroll_forward_command, _("\
1175 1.1.1.7 christos Scroll window forward.\n\
1176 1.1.1.7 christos Usage: + [N] [WIN]\n\
1177 1.1.1.6 christos Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\
1178 1.1.1.6 christos defaults to 1, and WIN defaults to the currently focused window."));
1179 1.1.1.7 christos add_com ("-", class_tui, tui_scroll_backward_command, _("\
1180 1.1.1.7 christos Scroll window backward.\n\
1181 1.1.1.7 christos Usage: - [N] [WIN]\n\
1182 1.1.1.6 christos Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\
1183 1.1.1.6 christos defaults to 1, and WIN defaults to the currently focused window."));
1184 1.1.1.7 christos add_com ("<", class_tui, tui_scroll_left_command, _("\
1185 1.1.1.7 christos Scroll window text to the left.\n\
1186 1.1.1.7 christos Usage: < [N] [WIN]\n\
1187 1.1.1.6 christos Scroll window WIN N characters left. Both WIN and N are optional, N\n\
1188 1.1.1.6 christos defaults to 1, and WIN defaults to the currently focused window."));
1189 1.1.1.7 christos add_com (">", class_tui, tui_scroll_right_command, _("\
1190 1.1.1.7 christos Scroll window text to the right.\n\
1191 1.1.1.7 christos Usage: > [N] [WIN]\n\
1192 1.1.1.6 christos Scroll window WIN N characters right. Both WIN and N are optional, N\n\
1193 1.1.1.6 christos defaults to 1, and WIN defaults to the currently focused window."));
1194 1.1.1.6 christos
1195 1.1.1.6 christos /* Define the tui control variables. */
1196 1.1.1.6 christos add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1197 1.1.1.6 christos &tui_border_kind, _("\
1198 1.1.1.6 christos Set the kind of border for TUI windows."), _("\
1199 1.1.1.7 christos Show the kind of border for TUI windows."), _("\
1200 1.1.1.7 christos This variable controls the border of TUI windows:\n\
1201 1.1.1.7 christos space use a white space\n\
1202 1.1.1.6 christos ascii use ascii characters + - | for the border\n\
1203 1.1.1.6 christos acs use the Alternate Character Set"),
1204 1.1.1.6 christos tui_set_var_cmd,
1205 1.1.1.6 christos show_tui_border_kind,
1206 1.1.1.9 christos &tui_setlist, &tui_showlist);
1207 1.1.1.7 christos
1208 1.1.1.7 christos const std::string help_attribute_mode (_("\
1209 1.1.1.7 christos normal normal display\n\
1210 1.1.1.7 christos standout use highlight mode of terminal\n\
1211 1.1.1.7 christos reverse use reverse video mode\n\
1212 1.1.1.7 christos half use half bright\n\
1213 1.1.1.9 christos half-standout use half bright and standout mode\n\
1214 1.1.1.9 christos bold use extra bright or bold\n\
1215 1.1.1.9 christos bold-standout use extra bright or bold with standout mode"));
1216 1.1.1.9 christos
1217 1.1.1.9 christos const std::string help_tui_border_mode
1218 1.1.1.9 christos = (_("\
1219 1.1.1.9 christos This variable controls the attributes to use for the window borders:\n")
1220 1.1.1.9 christos + help_attribute_mode);
1221 1.1.1.9 christos
1222 1.1.1.9 christos add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1223 1.1.1.9 christos &tui_border_mode, _("\
1224 1.1.1.9 christos Set the attribute mode to use for the TUI window borders."), _("\
1225 1.1.1.6 christos Show the attribute mode to use for the TUI window borders."),
1226 1.1.1.6 christos help_tui_border_mode.c_str (),
1227 1.1.1.6 christos tui_set_var_cmd,
1228 1.1.1.6 christos show_tui_border_mode,
1229 1.1.1.9 christos &tui_setlist, &tui_showlist);
1230 1.1.1.9 christos
1231 1.1.1.9 christos const std::string help_tui_active_border_mode
1232 1.1.1.9 christos = (_("\
1233 1.1.1.9 christos This variable controls the attributes to use for the active window borders:\n")
1234 1.1.1.6 christos + help_attribute_mode);
1235 1.1.1.6 christos
1236 1.1.1.6 christos add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1237 1.1.1.9 christos &tui_active_border_mode, _("\
1238 1.1.1.9 christos Set the attribute mode to use for the active TUI window border."), _("\
1239 1.1.1.6 christos Show the attribute mode to use for the active TUI window border."),
1240 1.1.1.6 christos help_tui_active_border_mode.c_str (),
1241 1.1.1.6 christos tui_set_var_cmd,
1242 1.1.1.6 christos show_tui_active_border_mode,
1243 1.1.1.6 christos &tui_setlist, &tui_showlist);
1244 1.1.1.6 christos
1245 1.1.1.6 christos add_setshow_zuinteger_cmd ("tab-width", no_class,
1246 1.1.1.9 christos &internal_tab_width, _("\
1247 1.1.1.6 christos Set the tab width, in characters, for the TUI."), _("\
1248 1.1.1.6 christos Show the tab width, in characters, for the TUI."), _("\
1249 1.1.1.6 christos This variable controls how many spaces are used to display a tab character."),
1250 1.1.1.7 christos tui_set_tab_width, tui_show_tab_width,
1251 1.1.1.7 christos &tui_setlist, &tui_showlist);
1252 1.1.1.7 christos
1253 1.1.1.7 christos add_setshow_boolean_cmd ("tui-resize-message", class_maintenance,
1254 1.1.1.7 christos &resize_message, _("\
1255 1.1.1.7 christos Set TUI resize messaging."), _("\
1256 1.1.1.7 christos Show TUI resize messaging."), _("\
1257 1.1.1.7 christos When enabled GDB will print a message when the terminal is resized."),
1258 1.1.1.7 christos nullptr,
1259 1.1.1.7 christos show_tui_resize_message,
1260 1.1.1.7 christos &maintenance_set_cmdlist,
1261 1.1.1.7 christos &maintenance_show_cmdlist);
1262 1.1.1.7 christos
1263 1.1.1.7 christos add_setshow_boolean_cmd ("compact-source", class_tui,
1264 1.1.1.7 christos &compact_source, _("\
1265 1.1.1.7 christos Set whether the TUI source window is compact."), _("\
1266 1.1.1.9 christos Show whether the TUI source window is compact."), _("\
1267 1.1.1.7 christos This variable controls whether the TUI source window is shown\n\
1268 1.1.1.7 christos in a compact form. The compact form uses less horizontal space."),
1269 1.1.1.7 christos tui_set_compact_source, tui_show_compact_source,
1270 1.1.1.9 christos &tui_setlist, &tui_showlist);
1271 1.1.1.9 christos
1272 1.1.1.9 christos add_setshow_boolean_cmd ("mouse-events", class_tui,
1273 1.1.1.9 christos &tui_enable_mouse, _("\
1274 1.1.1.9 christos Set whether TUI mode handles mouse clicks."), _("\
1275 1.1.1.9 christos Show whether TUI mode handles mouse clicks."), _("\
1276 1.1.1.9 christos When on (default), mouse clicks control the TUI and can be accessed by Python\n\
1277 1.1.1.9 christos extensions. When off, mouse clicks are handled by the terminal, enabling\n\
1278 1.1.1.9 christos terminal-native text selection."),
1279 1.1.1.9 christos nullptr,
1280 1.1.1.9 christos show_tui_mouse_events,
1281 1.1.1.8 christos &tui_setlist, &tui_showlist);
1282 1.1.1.8 christos
1283 1.1.1.8 christos add_setshow_boolean_cmd ("tui-current-position", class_maintenance,
1284 1.1.1.8 christos &style_tui_current_position, _("\
1285 1.1.1.8 christos Set whether to style text highlighted by the TUI's current position indicator."),
1286 1.1.1.8 christos _("\
1287 1.1.1.8 christos Show whether to style text highlighted by the TUI's current position indicator."),
1288 1.1.1.8 christos _("\
1289 1.1.1.8 christos When enabled, the source and assembly code highlighted by the TUI's current\n\
1290 1.1.1.8 christos position indicator is styled."),
1291 1.1.1.8 christos set_style_tui_current_position,
1292 1.1.1.8 christos show_style_tui_current_position,
1293 1.1.1.8 christos &style_set_list,
1294 1.1.1.9 christos &style_show_list);
1295 1.1.1.9 christos
1296 1.1.1.9 christos add_setshow_boolean_cmd ("tui-left-margin-verbose", class_maintenance,
1297 1.1.1.9 christos &tui_left_margin_verbose, _("\
1298 1.1.1.9 christos Set whether the left margin should use '_' and '0' instead of spaces."),
1299 1.1.1.9 christos _("\
1300 1.1.1.9 christos Show whether the left margin should use '_' and '0' instead of spaces."),
1301 1.1.1.9 christos _("\
1302 1.1.1.9 christos When enabled, the left margin will use '_' and '0' instead of spaces."),
1303 1.1.1.9 christos nullptr,
1304 1.1.1.9 christos nullptr,
1305 1.1.1.9 christos &maintenance_set_cmdlist,
1306 1.1.1.8 christos &maintenance_show_cmdlist);
1307 1.1.1.8 christos
1308 1.1.1.6 christos tui_border_style.changed.attach (tui_rehighlight_all, "tui-win");
1309 tui_active_border_style.changed.attach (tui_rehighlight_all, "tui-win");
1310 }
1311