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