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" |
d7b2e967 AC |
39 | #include "tui/tui-data.h" |
40 | #include "tui/tui-wingeneral.h" | |
41 | #include "tui/tui-stack.h" | |
42 | #include "tui/tui-regs.h" | |
43 | #include "tui/tui-disasm.h" | |
44 | #include "tui/tui-source.h" | |
45 | #include "tui/tui-winsource.h" | |
46 | #include "tui/tui-windata.h" | |
2c0b251b | 47 | #include "tui/tui-win.h" |
c906108c | 48 | |
6a83354a | 49 | #include "gdb_curses.h" |
96ec9981 | 50 | #include <ctype.h> |
dbda9972 | 51 | #include "readline/readline.h" |
96ec9981 | 52 | |
9612b5ec UW |
53 | #include <signal.h> |
54 | ||
c906108c SS |
55 | /******************************* |
56 | ** Static Local Decls | |
57 | ********************************/ | |
08ef48c5 MS |
58 | static void make_invisible_and_set_new_height (struct tui_win_info *, |
59 | int); | |
60 | static enum tui_status tui_adjust_win_heights (struct tui_win_info *, | |
61 | int); | |
6ba8e26f | 62 | static int new_height_ok (struct tui_win_info *, int); |
0b39b52e TT |
63 | static void tui_set_tab_width_command (const char *, int); |
64 | static void tui_refresh_all_command (const char *, int); | |
1d12d88f | 65 | static void tui_all_windows_info (const char *, int); |
0b39b52e TT |
66 | static void tui_set_focus_command (const char *, int); |
67 | static void tui_scroll_forward_command (const char *, int); | |
68 | static void tui_scroll_backward_command (const char *, int); | |
69 | static void tui_scroll_left_command (const char *, int); | |
70 | static void tui_scroll_right_command (const char *, int); | |
71 | static void parse_scrolling_args (const char *, | |
08ef48c5 MS |
72 | struct tui_win_info **, |
73 | int *); | |
c906108c SS |
74 | |
75 | ||
76 | /*************************************** | |
77 | ** DEFINITIONS | |
78 | ***************************************/ | |
57dbb3af | 79 | #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n" |
bf212be1 | 80 | #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n" |
c906108c SS |
81 | |
82 | /*************************************** | |
83 | ** PUBLIC FUNCTIONS | |
84 | ***************************************/ | |
85 | ||
17aae570 SC |
86 | #ifndef ACS_LRCORNER |
87 | # define ACS_LRCORNER '+' | |
88 | #endif | |
89 | #ifndef ACS_LLCORNER | |
90 | # define ACS_LLCORNER '+' | |
91 | #endif | |
92 | #ifndef ACS_ULCORNER | |
93 | # define ACS_ULCORNER '+' | |
94 | #endif | |
95 | #ifndef ACS_URCORNER | |
96 | # define ACS_URCORNER '+' | |
97 | #endif | |
98 | #ifndef ACS_HLINE | |
99 | # define ACS_HLINE '-' | |
100 | #endif | |
101 | #ifndef ACS_VLINE | |
102 | # define ACS_VLINE '|' | |
103 | #endif | |
104 | ||
af101512 | 105 | /* Possible values for tui-border-kind variable. */ |
40478521 | 106 | static const char *const tui_border_kind_enums[] = { |
af101512 SC |
107 | "space", |
108 | "ascii", | |
109 | "acs", | |
110 | NULL | |
111 | }; | |
112 | ||
113 | /* Possible values for tui-border-mode and tui-active-border-mode. */ | |
40478521 | 114 | static const char *const tui_border_mode_enums[] = { |
af101512 SC |
115 | "normal", |
116 | "standout", | |
117 | "reverse", | |
118 | "half", | |
119 | "half-standout", | |
120 | "bold", | |
121 | "bold-standout", | |
122 | NULL | |
123 | }; | |
124 | ||
125 | struct tui_translate | |
126 | { | |
127 | const char *name; | |
128 | int value; | |
129 | }; | |
130 | ||
131 | /* Translation table for border-mode variables. | |
132 | The list of values must be terminated by a NULL. | |
133 | After the NULL value, an entry defines the default. */ | |
134 | struct tui_translate tui_border_mode_translate[] = { | |
135 | { "normal", A_NORMAL }, | |
136 | { "standout", A_STANDOUT }, | |
137 | { "reverse", A_REVERSE }, | |
138 | { "half", A_DIM }, | |
139 | { "half-standout", A_DIM | A_STANDOUT }, | |
140 | { "bold", A_BOLD }, | |
141 | { "bold-standout", A_BOLD | A_STANDOUT }, | |
142 | { 0, 0 }, | |
143 | { "normal", A_NORMAL } | |
144 | }; | |
145 | ||
146 | /* Translation tables for border-kind, one for each border | |
147 | character (see wborder, border curses operations). | |
148 | -1 is used to indicate the ACS because ACS characters | |
149 | are determined at run time by curses (depends on terminal). */ | |
150 | struct tui_translate tui_border_kind_translate_vline[] = { | |
151 | { "space", ' ' }, | |
152 | { "ascii", '|' }, | |
153 | { "acs", -1 }, | |
154 | { 0, 0 }, | |
155 | { "ascii", '|' } | |
156 | }; | |
157 | ||
158 | struct tui_translate tui_border_kind_translate_hline[] = { | |
159 | { "space", ' ' }, | |
160 | { "ascii", '-' }, | |
161 | { "acs", -1 }, | |
162 | { 0, 0 }, | |
163 | { "ascii", '-' } | |
164 | }; | |
165 | ||
166 | struct tui_translate tui_border_kind_translate_ulcorner[] = { | |
167 | { "space", ' ' }, | |
168 | { "ascii", '+' }, | |
169 | { "acs", -1 }, | |
170 | { 0, 0 }, | |
171 | { "ascii", '+' } | |
172 | }; | |
173 | ||
174 | struct tui_translate tui_border_kind_translate_urcorner[] = { | |
175 | { "space", ' ' }, | |
176 | { "ascii", '+' }, | |
177 | { "acs", -1 }, | |
178 | { 0, 0 }, | |
179 | { "ascii", '+' } | |
180 | }; | |
181 | ||
182 | struct tui_translate tui_border_kind_translate_llcorner[] = { | |
183 | { "space", ' ' }, | |
184 | { "ascii", '+' }, | |
185 | { "acs", -1 }, | |
186 | { 0, 0 }, | |
187 | { "ascii", '+' } | |
188 | }; | |
189 | ||
190 | struct tui_translate tui_border_kind_translate_lrcorner[] = { | |
191 | { "space", ' ' }, | |
192 | { "ascii", '+' }, | |
193 | { "acs", -1 }, | |
194 | { 0, 0 }, | |
195 | { "ascii", '+' } | |
196 | }; | |
197 | ||
198 | ||
199 | /* Tui configuration variables controlled with set/show command. */ | |
200 | const char *tui_active_border_mode = "bold-standout"; | |
920d2a44 | 201 | static void |
08ef48c5 MS |
202 | show_tui_active_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 active TUI window border is \"%s\".\n"), | |
209 | value); | |
210 | } | |
211 | ||
af101512 | 212 | const char *tui_border_mode = "normal"; |
920d2a44 | 213 | static void |
08ef48c5 MS |
214 | show_tui_border_mode (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, _("\ | |
220 | The attribute mode to use for the TUI window borders is \"%s\".\n"), | |
221 | value); | |
222 | } | |
223 | ||
af101512 | 224 | const char *tui_border_kind = "acs"; |
920d2a44 | 225 | static void |
08ef48c5 MS |
226 | show_tui_border_kind (struct ui_file *file, |
227 | int from_tty, | |
228 | struct cmd_list_element *c, | |
229 | const char *value) | |
920d2a44 AC |
230 | { |
231 | fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"), | |
232 | value); | |
233 | } | |
234 | ||
af101512 | 235 | |
1cc6d956 MS |
236 | /* Tui internal configuration variables. These variables are updated |
237 | by tui_update_variables to reflect the tui configuration | |
af101512 SC |
238 | variables. */ |
239 | chtype tui_border_vline; | |
240 | chtype tui_border_hline; | |
241 | chtype tui_border_ulcorner; | |
242 | chtype tui_border_urcorner; | |
243 | chtype tui_border_llcorner; | |
244 | chtype tui_border_lrcorner; | |
245 | ||
246 | int tui_border_attrs; | |
247 | int tui_active_border_attrs; | |
248 | ||
249 | /* Identify the item in the translation table. | |
250 | When the item is not recognized, use the default entry. */ | |
251 | static struct tui_translate * | |
252 | translate (const char *name, struct tui_translate *table) | |
253 | { | |
254 | while (table->name) | |
255 | { | |
256 | if (name && strcmp (table->name, name) == 0) | |
257 | return table; | |
258 | table++; | |
259 | } | |
260 | ||
261 | /* Not found, return default entry. */ | |
262 | table++; | |
263 | return table; | |
264 | } | |
265 | ||
266 | /* Update the tui internal configuration according to gdb settings. | |
267 | Returns 1 if the configuration has changed and the screen should | |
268 | be redrawn. */ | |
269 | int | |
d02c80cd | 270 | tui_update_variables (void) |
af101512 SC |
271 | { |
272 | int need_redraw = 0; | |
273 | struct tui_translate *entry; | |
274 | ||
275 | entry = translate (tui_border_mode, tui_border_mode_translate); | |
276 | if (tui_border_attrs != entry->value) | |
277 | { | |
278 | tui_border_attrs = entry->value; | |
279 | need_redraw = 1; | |
280 | } | |
281 | entry = translate (tui_active_border_mode, tui_border_mode_translate); | |
282 | if (tui_active_border_attrs != entry->value) | |
283 | { | |
284 | tui_active_border_attrs = entry->value; | |
285 | need_redraw = 1; | |
286 | } | |
287 | ||
288 | /* If one corner changes, all characters are changed. | |
289 | Only check the first one. The ACS characters are determined at | |
290 | run time by curses terminal management. */ | |
291 | entry = translate (tui_border_kind, tui_border_kind_translate_lrcorner); | |
292 | if (tui_border_lrcorner != (chtype) entry->value) | |
293 | { | |
294 | tui_border_lrcorner = (entry->value < 0) ? ACS_LRCORNER : entry->value; | |
295 | need_redraw = 1; | |
296 | } | |
297 | entry = translate (tui_border_kind, tui_border_kind_translate_llcorner); | |
298 | tui_border_llcorner = (entry->value < 0) ? ACS_LLCORNER : entry->value; | |
299 | ||
300 | entry = translate (tui_border_kind, tui_border_kind_translate_ulcorner); | |
301 | tui_border_ulcorner = (entry->value < 0) ? ACS_ULCORNER : entry->value; | |
302 | ||
303 | entry = translate (tui_border_kind, tui_border_kind_translate_urcorner); | |
304 | tui_border_urcorner = (entry->value < 0) ? ACS_URCORNER : entry->value; | |
305 | ||
306 | entry = translate (tui_border_kind, tui_border_kind_translate_hline); | |
307 | tui_border_hline = (entry->value < 0) ? ACS_HLINE : entry->value; | |
308 | ||
309 | entry = translate (tui_border_kind, tui_border_kind_translate_vline); | |
310 | tui_border_vline = (entry->value < 0) ? ACS_VLINE : entry->value; | |
311 | ||
312 | return need_redraw; | |
313 | } | |
314 | ||
c9684879 | 315 | static void |
981a3fb3 | 316 | set_tui_cmd (const char *args, int from_tty) |
c9684879 SC |
317 | { |
318 | } | |
319 | ||
320 | static void | |
981a3fb3 | 321 | show_tui_cmd (const char *args, int from_tty) |
c9684879 SC |
322 | { |
323 | } | |
af101512 | 324 | |
10f59415 SC |
325 | static struct cmd_list_element *tuilist; |
326 | ||
327 | static void | |
981a3fb3 | 328 | tui_command (const char *args, int from_tty) |
10f59415 | 329 | { |
a3f17187 AC |
330 | printf_unfiltered (_("\"tui\" must be followed by the name of a " |
331 | "tui command.\n")); | |
635c7e8a | 332 | help_list (tuilist, "tui ", all_commands, gdb_stdout); |
10f59415 SC |
333 | } |
334 | ||
335 | struct cmd_list_element ** | |
da745b36 | 336 | tui_get_cmd_list (void) |
10f59415 SC |
337 | { |
338 | if (tuilist == 0) | |
339 | add_prefix_cmd ("tui", class_tui, tui_command, | |
1bedd215 | 340 | _("Text User Interface commands."), |
10f59415 SC |
341 | &tuilist, "tui ", 0, &cmdlist); |
342 | return &tuilist; | |
343 | } | |
344 | ||
6cdb25f4 EZ |
345 | /* The set_func hook of "set tui ..." commands that affect the window |
346 | borders on the TUI display. */ | |
347 | void | |
eb4c3f4a TT |
348 | tui_set_var_cmd (const char *null_args, |
349 | int from_tty, struct cmd_list_element *c) | |
6cdb25f4 EZ |
350 | { |
351 | if (tui_update_variables () && tui_active) | |
352 | tui_rehighlight_all (); | |
353 | } | |
354 | ||
97605e61 AB |
355 | /* Generic window name completion function. Complete window name pointed |
356 | to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special | |
357 | window names 'next' and 'prev' will also be considered as possible | |
358 | completions of the window name. */ | |
2e52ae68 | 359 | |
eb3ff9a5 PA |
360 | static void |
361 | window_name_completer (completion_tracker &tracker, | |
362 | int include_next_prev_p, | |
97605e61 | 363 | const char *text, const char *word) |
2e52ae68 | 364 | { |
625ad440 | 365 | std::vector<const char *> completion_name_vec; |
2e52ae68 | 366 | |
1ce3e844 | 367 | for (tui_win_info *win_info : all_tui_windows ()) |
2e52ae68 PP |
368 | { |
369 | const char *completion_name = NULL; | |
370 | ||
371 | /* We can't focus on an invisible window. */ | |
1ce3e844 | 372 | if (!win_info->is_visible) |
2e52ae68 PP |
373 | continue; |
374 | ||
1ce3e844 | 375 | completion_name = win_info->name (); |
150375dc | 376 | gdb_assert (completion_name != NULL); |
625ad440 | 377 | completion_name_vec.push_back (completion_name); |
2e52ae68 PP |
378 | } |
379 | ||
380 | /* If no windows are considered visible then the TUI has not yet been | |
381 | initialized. But still "focus src" and "focus cmd" will work because | |
382 | invoking the focus command will entail initializing the TUI which sets the | |
383 | default layout to SRC_COMMAND. */ | |
625ad440 | 384 | if (completion_name_vec.empty ()) |
2e52ae68 | 385 | { |
625ad440 SM |
386 | completion_name_vec.push_back (SRC_NAME); |
387 | completion_name_vec.push_back (CMD_NAME); | |
2e52ae68 PP |
388 | } |
389 | ||
97605e61 AB |
390 | if (include_next_prev_p) |
391 | { | |
625ad440 SM |
392 | completion_name_vec.push_back ("next"); |
393 | completion_name_vec.push_back ("prev"); | |
97605e61 | 394 | } |
2e52ae68 | 395 | |
2e52ae68 | 396 | |
625ad440 SM |
397 | completion_name_vec.push_back (NULL); |
398 | complete_on_enum (tracker, completion_name_vec.data (), text, word); | |
2e52ae68 PP |
399 | } |
400 | ||
97605e61 AB |
401 | /* Complete possible window names to focus on. TEXT is the complete text |
402 | entered so far, WORD is the word currently being completed. */ | |
403 | ||
eb3ff9a5 | 404 | static void |
97605e61 | 405 | focus_completer (struct cmd_list_element *ignore, |
eb3ff9a5 PA |
406 | completion_tracker &tracker, |
407 | const char *text, const char *word) | |
97605e61 | 408 | { |
eb3ff9a5 | 409 | window_name_completer (tracker, 1, text, word); |
97605e61 AB |
410 | } |
411 | ||
412 | /* Complete possible window names for winheight command. TEXT is the | |
413 | complete text entered so far, WORD is the word currently being | |
414 | completed. */ | |
415 | ||
eb3ff9a5 | 416 | static void |
97605e61 | 417 | winheight_completer (struct cmd_list_element *ignore, |
eb3ff9a5 | 418 | completion_tracker &tracker, |
97605e61 AB |
419 | const char *text, const char *word) |
420 | { | |
421 | /* The first word is the window name. That we can complete. Subsequent | |
422 | words can't be completed. */ | |
423 | if (word != text) | |
eb3ff9a5 | 424 | return; |
97605e61 | 425 | |
eb3ff9a5 | 426 | window_name_completer (tracker, 0, text, word); |
97605e61 AB |
427 | } |
428 | ||
3e752b04 SC |
429 | /* Update gdb's knowledge of the terminal size. */ |
430 | void | |
d02c80cd | 431 | tui_update_gdb_sizes (void) |
3e752b04 | 432 | { |
d6e5e7f7 PP |
433 | int width, height; |
434 | ||
435 | if (tui_active) | |
436 | { | |
cb2ce893 TT |
437 | width = TUI_CMD_WIN->width; |
438 | height = TUI_CMD_WIN->height; | |
d6e5e7f7 PP |
439 | } |
440 | else | |
441 | { | |
442 | width = tui_term_width (); | |
443 | height = tui_term_height (); | |
444 | } | |
445 | ||
446 | set_screen_width_and_height (width, height); | |
3e752b04 SC |
447 | } |
448 | ||
c906108c | 449 | |
1cc6d956 | 450 | /* Set the logical focus to win_info. */ |
c906108c | 451 | void |
5b6fe301 | 452 | tui_set_win_focus_to (struct tui_win_info *win_info) |
c906108c | 453 | { |
6d012f14 | 454 | if (win_info != NULL) |
c906108c | 455 | { |
5b6fe301 | 456 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
c906108c | 457 | |
bbc228ee | 458 | tui_unhighlight_win (win_with_focus); |
6d012f14 | 459 | tui_set_win_with_focus (win_info); |
bbc228ee | 460 | tui_highlight_win (win_info); |
c906108c | 461 | } |
6ba8e26f | 462 | } |
c906108c SS |
463 | |
464 | ||
c906108c | 465 | void |
13446e05 | 466 | tui_win_info::forward_scroll (int num_to_scroll) |
c906108c | 467 | { |
13446e05 | 468 | if (num_to_scroll == 0) |
cb2ce893 | 469 | num_to_scroll = height - 3; |
c906108c | 470 | |
c3bd716f | 471 | do_scroll_vertical (num_to_scroll); |
a21fcd8f | 472 | } |
c906108c | 473 | |
c906108c | 474 | void |
13446e05 | 475 | tui_win_info::backward_scroll (int num_to_scroll) |
c906108c | 476 | { |
13446e05 | 477 | if (num_to_scroll == 0) |
cb2ce893 | 478 | num_to_scroll = height - 3; |
13446e05 | 479 | |
c3bd716f | 480 | do_scroll_vertical (-num_to_scroll); |
a21fcd8f | 481 | } |
c906108c SS |
482 | |
483 | ||
c906108c | 484 | void |
13446e05 | 485 | tui_win_info::left_scroll (int num_to_scroll) |
c906108c | 486 | { |
13446e05 TT |
487 | if (num_to_scroll == 0) |
488 | num_to_scroll = 1; | |
489 | ||
c3bd716f | 490 | do_scroll_horizontal (num_to_scroll); |
a21fcd8f | 491 | } |
c906108c SS |
492 | |
493 | ||
c906108c | 494 | void |
13446e05 | 495 | tui_win_info::right_scroll (int num_to_scroll) |
c906108c | 496 | { |
13446e05 TT |
497 | if (num_to_scroll == 0) |
498 | num_to_scroll = 1; | |
499 | ||
c3bd716f | 500 | do_scroll_horizontal (-num_to_scroll); |
e8b915dc | 501 | } |
c906108c SS |
502 | |
503 | ||
1825f487 TT |
504 | /* See tui-data.h. */ |
505 | ||
506 | void | |
507 | tui_source_window_base::refresh_all () | |
508 | { | |
509 | tui_show_source_content (this); | |
510 | tui_check_and_display_highlight_if_needed (this); | |
511 | tui_erase_exec_info_content (this); | |
512 | tui_update_exec_info (this); | |
513 | } | |
514 | ||
c906108c | 515 | void |
a21fcd8f | 516 | tui_refresh_all_win (void) |
c906108c | 517 | { |
3e266828 | 518 | clearok (curscr, TRUE); |
1ce3e844 TT |
519 | tui_refresh_all (); |
520 | for (tui_win_info *win_info : all_tui_windows ()) | |
c906108c | 521 | { |
1ce3e844 TT |
522 | if (win_info->is_visible) |
523 | win_info->refresh_all (); | |
c906108c | 524 | } |
47d3492a | 525 | tui_show_locator_content (); |
bc712bbf | 526 | } |
c906108c | 527 | |
6cdb25f4 EZ |
528 | void |
529 | tui_rehighlight_all (void) | |
530 | { | |
1ce3e844 TT |
531 | for (tui_win_info *win_info : all_tui_windows ()) |
532 | tui_check_and_display_highlight_if_needed (win_info); | |
6cdb25f4 | 533 | } |
c906108c | 534 | |
b021a221 | 535 | /* Resize all the windows based on the terminal size. This function |
ae2b5380 | 536 | gets called from within the readline SIGWINCH handler. */ |
c906108c | 537 | void |
6ba8e26f | 538 | tui_resize_all (void) |
c906108c | 539 | { |
6ba8e26f | 540 | int height_diff, width_diff; |
9255ee31 | 541 | int screenheight, screenwidth; |
c906108c | 542 | |
9255ee31 | 543 | rl_get_screen_size (&screenheight, &screenwidth); |
6ba8e26f AC |
544 | width_diff = screenwidth - tui_term_width (); |
545 | height_diff = screenheight - tui_term_height (); | |
546 | if (height_diff || width_diff) | |
c906108c | 547 | { |
6ba8e26f | 548 | enum tui_layout_type cur_layout = tui_current_layout (); |
5b6fe301 | 549 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
6ba8e26f AC |
550 | struct tui_win_info *first_win; |
551 | struct tui_win_info *second_win; | |
7908abbf | 552 | tui_source_window_base *src_win; |
3add462f | 553 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
570dc176 | 554 | int win_type; |
6ba8e26f | 555 | int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2; |
c906108c | 556 | |
10f59415 SC |
557 | #ifdef HAVE_RESIZE_TERM |
558 | resize_term (screenheight, screenwidth); | |
559 | #endif | |
1cc6d956 | 560 | /* Turn keypad off while we resize. */ |
6ba8e26f | 561 | if (win_with_focus != TUI_CMD_WIN) |
cb2ce893 | 562 | keypad (TUI_CMD_WIN->handle, FALSE); |
3e752b04 | 563 | tui_update_gdb_sizes (); |
dd1abb8c AC |
564 | tui_set_term_height_to (screenheight); |
565 | tui_set_term_width_to (screenwidth); | |
e5908723 MS |
566 | if (cur_layout == SRC_DISASSEM_COMMAND |
567 | || cur_layout == SRC_DATA_COMMAND | |
568 | || cur_layout == DISASSEM_DATA_COMMAND) | |
6ba8e26f AC |
569 | num_wins_displayed++; |
570 | split_diff = height_diff / num_wins_displayed; | |
571 | cmd_split_diff = split_diff; | |
572 | if (height_diff % num_wins_displayed) | |
c906108c | 573 | { |
6ba8e26f AC |
574 | if (height_diff < 0) |
575 | cmd_split_diff--; | |
c906108c | 576 | else |
c366c1f0 TT |
577 | cmd_split_diff++; |
578 | } | |
1cc6d956 | 579 | /* Now adjust each window. */ |
c366c1f0 TT |
580 | /* erase + clearok are used instead of a straightforward clear as |
581 | AIX 5.3 does not define clear. */ | |
582 | erase (); | |
583 | clearok (curscr, TRUE); | |
c906108c | 584 | refresh (); |
6ba8e26f | 585 | switch (cur_layout) |
c366c1f0 | 586 | { |
c906108c SS |
587 | case SRC_COMMAND: |
588 | case DISASSEM_COMMAND: | |
7908abbf TT |
589 | src_win = tui_source_windows ()[0]; |
590 | first_win = src_win; | |
cb2ce893 | 591 | first_win->width += width_diff; |
6ba8e26f | 592 | locator->width += width_diff; |
1cc6d956 | 593 | /* Check for invalid heights. */ |
6ba8e26f | 594 | if (height_diff == 0) |
cb2ce893 TT |
595 | new_height = first_win->height; |
596 | else if ((first_win->height + split_diff) >= | |
c906108c | 597 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f | 598 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
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 | |
0036e657 | 604 | locator->origin.y = new_height + 1; |
6ba8e26f | 605 | make_invisible_and_set_new_height (first_win, new_height); |
cb2ce893 TT |
606 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
607 | TUI_CMD_WIN->width += width_diff; | |
608 | new_height = screenheight - TUI_CMD_WIN->origin.y; | |
6ba8e26f | 609 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
5fcee43a TT |
610 | first_win->make_visible_with_new_height (); |
611 | TUI_CMD_WIN->make_visible_with_new_height (); | |
53e7cdba | 612 | if (src_win->content.empty ()) |
caf0bc4e | 613 | tui_erase_source_content (src_win); |
c906108c SS |
614 | break; |
615 | default: | |
6ba8e26f | 616 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 617 | { |
7908abbf TT |
618 | src_win = TUI_SRC_WIN; |
619 | first_win = src_win; | |
cb2ce893 | 620 | first_win->width += width_diff; |
6ba8e26f | 621 | second_win = TUI_DISASM_WIN; |
cb2ce893 | 622 | second_win->width += width_diff; |
c906108c SS |
623 | } |
624 | else | |
625 | { | |
6ba8e26f | 626 | first_win = TUI_DATA_WIN; |
cb2ce893 | 627 | first_win->width += width_diff; |
7908abbf TT |
628 | src_win = tui_source_windows ()[0]; |
629 | second_win = src_win; | |
cb2ce893 | 630 | second_win->width += width_diff; |
c906108c | 631 | } |
1cc6d956 MS |
632 | /* Change the first window's height/width. */ |
633 | /* Check for invalid heights. */ | |
6ba8e26f | 634 | if (height_diff == 0) |
cb2ce893 TT |
635 | new_height = first_win->height; |
636 | else if ((first_win->height + | |
637 | second_win->height + (split_diff * 2)) >= | |
c906108c | 638 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
6ba8e26f | 639 | new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2; |
cb2ce893 | 640 | else if ((first_win->height + split_diff) <= 0) |
6ba8e26f | 641 | new_height = MIN_WIN_HEIGHT; |
c906108c | 642 | else |
cb2ce893 | 643 | new_height = first_win->height + split_diff; |
6ba8e26f | 644 | make_invisible_and_set_new_height (first_win, new_height); |
c906108c | 645 | |
6ba8e26f | 646 | locator->width += width_diff; |
c906108c | 647 | |
1cc6d956 MS |
648 | /* Change the second window's height/width. */ |
649 | /* Check for invalid heights. */ | |
6ba8e26f | 650 | if (height_diff == 0) |
cb2ce893 TT |
651 | new_height = second_win->height; |
652 | else if ((first_win->height + | |
653 | second_win->height + (split_diff * 2)) >= | |
c906108c SS |
654 | (screenheight - MIN_CMD_WIN_HEIGHT - 1)) |
655 | { | |
6ba8e26f AC |
656 | new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1; |
657 | if (new_height % 2) | |
658 | new_height = (new_height / 2) + 1; | |
c906108c | 659 | else |
6ba8e26f | 660 | new_height /= 2; |
c906108c | 661 | } |
cb2ce893 | 662 | else if ((second_win->height + split_diff) <= 0) |
6ba8e26f | 663 | new_height = MIN_WIN_HEIGHT; |
c906108c | 664 | else |
cb2ce893 TT |
665 | new_height = second_win->height + split_diff; |
666 | second_win->origin.y = first_win->height - 1; | |
6ba8e26f | 667 | make_invisible_and_set_new_height (second_win, new_height); |
c906108c | 668 | |
1cc6d956 | 669 | /* Change the command window's height/width. */ |
cb2ce893 | 670 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
9a2b4c1b | 671 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
cb2ce893 | 672 | TUI_CMD_WIN->height |
9a2b4c1b | 673 | + cmd_split_diff); |
5fcee43a TT |
674 | first_win->make_visible_with_new_height (); |
675 | second_win->make_visible_with_new_height (); | |
676 | TUI_CMD_WIN->make_visible_with_new_height (); | |
53e7cdba | 677 | if (src_win->content.empty ()) |
caf0bc4e | 678 | tui_erase_source_content (src_win); |
c906108c SS |
679 | break; |
680 | } | |
ef5eab5a MS |
681 | /* Now remove all invisible windows, and their content so that |
682 | they get created again when called for with the new size. */ | |
6ba8e26f | 683 | for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++) |
c906108c | 684 | { |
e5908723 MS |
685 | if (win_type != CMD_WIN |
686 | && (tui_win_list[win_type] != NULL) | |
cb2ce893 | 687 | && !tui_win_list[win_type]->is_visible) |
c906108c | 688 | { |
e7e11af4 | 689 | delete tui_win_list[win_type]; |
e65b5245 | 690 | tui_win_list[win_type] = NULL; |
c906108c SS |
691 | } |
692 | } | |
1cc6d956 MS |
693 | /* Turn keypad back on, unless focus is in the command |
694 | window. */ | |
6ba8e26f | 695 | if (win_with_focus != TUI_CMD_WIN) |
cb2ce893 | 696 | keypad (TUI_CMD_WIN->handle, TRUE); |
c906108c | 697 | } |
6ba8e26f | 698 | } |
c906108c | 699 | |
2c0b251b | 700 | #ifdef SIGWINCH |
c4ef48c6 PP |
701 | /* Token for use by TUI's asynchronous SIGWINCH handler. */ |
702 | static struct async_signal_handler *tui_sigwinch_token; | |
703 | ||
704 | /* TUI's SIGWINCH signal handler. */ | |
2c0b251b | 705 | static void |
6ba8e26f | 706 | tui_sigwinch_handler (int signal) |
c906108c | 707 | { |
c4ef48c6 | 708 | mark_async_signal_handler (tui_sigwinch_token); |
dd1abb8c | 709 | tui_set_win_resized_to (TRUE); |
6ba8e26f | 710 | } |
c4ef48c6 PP |
711 | |
712 | /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */ | |
713 | static void | |
714 | tui_async_resize_screen (gdb_client_data arg) | |
715 | { | |
a88d0bb3 PP |
716 | rl_resize_terminal (); |
717 | ||
c4ef48c6 | 718 | if (!tui_active) |
a88d0bb3 PP |
719 | { |
720 | int screen_height, screen_width; | |
c4ef48c6 | 721 | |
a88d0bb3 PP |
722 | rl_get_screen_size (&screen_height, &screen_width); |
723 | set_screen_width_and_height (screen_width, screen_height); | |
724 | ||
725 | /* win_resized is left set so that the next call to tui_enable() | |
726 | resizes the TUI windows. */ | |
727 | } | |
728 | else | |
729 | { | |
1e04046d | 730 | tui_set_win_resized_to (FALSE); |
a88d0bb3 PP |
731 | tui_resize_all (); |
732 | tui_refresh_all_win (); | |
733 | tui_update_gdb_sizes (); | |
a88d0bb3 PP |
734 | tui_redisplay_readline (); |
735 | } | |
c4ef48c6 | 736 | } |
2c0b251b | 737 | #endif |
c906108c | 738 | |
c4ef48c6 PP |
739 | /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not |
740 | uninstalled when we exit TUI, so the handler should not assume that TUI is | |
741 | always active. */ | |
9612b5ec UW |
742 | void |
743 | tui_initialize_win (void) | |
744 | { | |
745 | #ifdef SIGWINCH | |
c4ef48c6 PP |
746 | tui_sigwinch_token |
747 | = create_async_signal_handler (tui_async_resize_screen, NULL); | |
748 | ||
749 | { | |
9612b5ec | 750 | #ifdef HAVE_SIGACTION |
c4ef48c6 | 751 | struct sigaction old_winch; |
1c5313c5 | 752 | |
c4ef48c6 PP |
753 | memset (&old_winch, 0, sizeof (old_winch)); |
754 | old_winch.sa_handler = &tui_sigwinch_handler; | |
a344fc09 | 755 | #ifdef SA_RESTART |
c4ef48c6 | 756 | old_winch.sa_flags = SA_RESTART; |
a344fc09 | 757 | #endif |
c4ef48c6 | 758 | sigaction (SIGWINCH, &old_winch, NULL); |
9612b5ec | 759 | #else |
c4ef48c6 | 760 | signal (SIGWINCH, &tui_sigwinch_handler); |
9612b5ec | 761 | #endif |
c4ef48c6 | 762 | } |
9612b5ec UW |
763 | #endif |
764 | } | |
c906108c SS |
765 | |
766 | ||
767 | /************************* | |
768 | ** STATIC LOCAL FUNCTIONS | |
769 | **************************/ | |
770 | ||
771 | ||
c906108c | 772 | static void |
0b39b52e | 773 | tui_scroll_forward_command (const char *arg, int from_tty) |
c906108c | 774 | { |
6ba8e26f | 775 | int num_to_scroll = 1; |
5b6fe301 | 776 | struct tui_win_info *win_to_scroll; |
c906108c | 777 | |
1854bb21 SC |
778 | /* Make sure the curses mode is enabled. */ |
779 | tui_enable (); | |
63a33118 | 780 | if (arg == NULL) |
cafb3438 | 781 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
c906108c | 782 | else |
6ba8e26f | 783 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 784 | win_to_scroll->forward_scroll (num_to_scroll); |
e8b915dc | 785 | } |
c906108c SS |
786 | |
787 | ||
c906108c | 788 | static void |
0b39b52e | 789 | tui_scroll_backward_command (const char *arg, int from_tty) |
c906108c | 790 | { |
6ba8e26f | 791 | int num_to_scroll = 1; |
5b6fe301 | 792 | struct tui_win_info *win_to_scroll; |
c906108c | 793 | |
1854bb21 SC |
794 | /* Make sure the curses mode is enabled. */ |
795 | tui_enable (); | |
63a33118 | 796 | if (arg == NULL) |
cafb3438 | 797 | parse_scrolling_args (arg, &win_to_scroll, NULL); |
c906108c | 798 | else |
6ba8e26f | 799 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 800 | win_to_scroll->backward_scroll (num_to_scroll); |
e8b915dc | 801 | } |
c906108c SS |
802 | |
803 | ||
c906108c | 804 | static void |
0b39b52e | 805 | tui_scroll_left_command (const char *arg, int from_tty) |
c906108c | 806 | { |
6ba8e26f | 807 | int num_to_scroll; |
5b6fe301 | 808 | struct tui_win_info *win_to_scroll; |
c906108c | 809 | |
1854bb21 SC |
810 | /* Make sure the curses mode is enabled. */ |
811 | tui_enable (); | |
6ba8e26f | 812 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 813 | win_to_scroll->left_scroll (num_to_scroll); |
e8b915dc | 814 | } |
c906108c SS |
815 | |
816 | ||
c906108c | 817 | static void |
0b39b52e | 818 | tui_scroll_right_command (const char *arg, int from_tty) |
c906108c | 819 | { |
6ba8e26f | 820 | int num_to_scroll; |
5b6fe301 | 821 | struct tui_win_info *win_to_scroll; |
c906108c | 822 | |
1854bb21 SC |
823 | /* Make sure the curses mode is enabled. */ |
824 | tui_enable (); | |
6ba8e26f | 825 | parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll); |
13446e05 | 826 | win_to_scroll->right_scroll (num_to_scroll); |
e8b915dc | 827 | } |
c906108c SS |
828 | |
829 | ||
6ba8e26f | 830 | /* Set focus to the window named by 'arg'. */ |
c906108c | 831 | static void |
0b39b52e | 832 | tui_set_focus (const char *arg, int from_tty) |
c906108c | 833 | { |
63a33118 | 834 | if (arg != NULL) |
c906108c | 835 | { |
63a33118 | 836 | char *buf_ptr = xstrdup (arg); |
c906108c | 837 | int i; |
e65b5245 | 838 | struct tui_win_info *win_info = NULL; |
c906108c | 839 | |
6ba8e26f | 840 | for (i = 0; (i < strlen (buf_ptr)); i++) |
6dce28e4 | 841 | buf_ptr[i] = tolower (arg[i]); |
c906108c | 842 | |
6dce28e4 | 843 | if (subset_compare (buf_ptr, "next")) |
6d012f14 | 844 | win_info = tui_next_win (tui_win_with_focus ()); |
6dce28e4 | 845 | else if (subset_compare (buf_ptr, "prev")) |
6d012f14 | 846 | win_info = tui_prev_win (tui_win_with_focus ()); |
c906108c | 847 | else |
6ba8e26f | 848 | win_info = tui_partial_win_by_name (buf_ptr); |
c906108c | 849 | |
cb2ce893 | 850 | if (win_info == NULL || !win_info->is_visible) |
8a3fe4f8 AC |
851 | warning (_("Invalid window specified. \n\ |
852 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
853 | else |
854 | { | |
6d012f14 | 855 | tui_set_win_focus_to (win_info); |
cb2ce893 | 856 | keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN)); |
c906108c SS |
857 | } |
858 | ||
cb2ce893 | 859 | if (TUI_DATA_WIN && TUI_DATA_WIN->is_visible) |
1825f487 | 860 | TUI_DATA_WIN->refresh_all (); |
6ba8e26f | 861 | xfree (buf_ptr); |
a3f17187 | 862 | printf_filtered (_("Focus set to %s window.\n"), |
152f3f4b | 863 | tui_win_with_focus ()->name ()); |
c906108c SS |
864 | } |
865 | else | |
8a3fe4f8 | 866 | warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE); |
6ba8e26f | 867 | } |
c906108c | 868 | |
c906108c | 869 | static void |
0b39b52e | 870 | tui_set_focus_command (const char *arg, int from_tty) |
c906108c | 871 | { |
1854bb21 SC |
872 | /* Make sure the curses mode is enabled. */ |
873 | tui_enable (); | |
6ba8e26f | 874 | tui_set_focus (arg, from_tty); |
e8b915dc | 875 | } |
c906108c SS |
876 | |
877 | ||
c906108c | 878 | static void |
1d12d88f | 879 | tui_all_windows_info (const char *arg, int from_tty) |
c906108c | 880 | { |
5b6fe301 | 881 | struct tui_win_info *win_with_focus = tui_win_with_focus (); |
c906108c | 882 | |
1ce3e844 TT |
883 | for (tui_win_info *win_info : all_tui_windows ()) |
884 | if (win_info->is_visible) | |
c906108c | 885 | { |
1ce3e844 | 886 | if (win_with_focus == win_info) |
c906108c | 887 | printf_filtered (" %s\t(%d lines) <has focus>\n", |
1ce3e844 TT |
888 | win_info->name (), |
889 | win_info->height); | |
c906108c SS |
890 | else |
891 | printf_filtered (" %s\t(%d lines)\n", | |
1ce3e844 TT |
892 | win_info->name (), |
893 | win_info->height); | |
c906108c | 894 | } |
6ba8e26f | 895 | } |
c906108c SS |
896 | |
897 | ||
c906108c | 898 | static void |
0b39b52e | 899 | tui_refresh_all_command (const char *arg, int from_tty) |
c906108c | 900 | { |
1854bb21 SC |
901 | /* Make sure the curses mode is enabled. */ |
902 | tui_enable (); | |
903 | ||
a21fcd8f | 904 | tui_refresh_all_win (); |
c906108c SS |
905 | } |
906 | ||
7806cea7 TT |
907 | /* The tab width that should be used by the TUI. */ |
908 | ||
909 | unsigned int tui_tab_width = DEFAULT_TAB_LEN; | |
910 | ||
911 | /* The tab width as set by the user. */ | |
912 | ||
913 | static unsigned int internal_tab_width = DEFAULT_TAB_LEN; | |
914 | ||
d83f1fe6 | 915 | /* See tui-data.h. */ |
7806cea7 | 916 | |
d83f1fe6 TT |
917 | void |
918 | tui_source_window_base::update_tab_width () | |
7806cea7 TT |
919 | { |
920 | /* We don't really change the height of any windows, but | |
921 | calling these 2 functions causes a complete regeneration | |
922 | and redisplay of the window's contents, which will take | |
923 | the new tab width into account. */ | |
d83f1fe6 | 924 | make_invisible_and_set_new_height (this, height); |
5fcee43a | 925 | make_visible_with_new_height (); |
d83f1fe6 TT |
926 | } |
927 | ||
928 | /* After the tab width is set, call this to update the relevant | |
929 | windows. */ | |
930 | ||
931 | static void | |
932 | update_tab_width () | |
933 | { | |
1ce3e844 | 934 | for (tui_win_info *win_info : all_tui_windows ()) |
7806cea7 | 935 | { |
1ce3e844 TT |
936 | if (win_info->is_visible) |
937 | win_info->update_tab_width (); | |
7806cea7 TT |
938 | } |
939 | } | |
940 | ||
941 | /* Callback for "set tui tab-width". */ | |
942 | ||
943 | static void | |
944 | tui_set_tab_width (const char *ignore, | |
945 | int from_tty, struct cmd_list_element *c) | |
946 | { | |
947 | if (internal_tab_width == 0) | |
948 | { | |
949 | internal_tab_width = tui_tab_width; | |
950 | error (_("Tab width must not be 0")); | |
951 | } | |
952 | ||
953 | tui_tab_width = internal_tab_width; | |
954 | update_tab_width (); | |
955 | } | |
956 | ||
957 | /* Callback for "show tui tab-width". */ | |
958 | ||
959 | static void | |
960 | tui_show_tab_width (struct ui_file *file, int from_tty, | |
961 | struct cmd_list_element *c, const char *value) | |
962 | { | |
963 | fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value); | |
964 | ||
965 | } | |
c906108c | 966 | |
c54da50d | 967 | /* Set the tab width of the specified window. */ |
c906108c | 968 | static void |
0b39b52e | 969 | tui_set_tab_width_command (const char *arg, int from_tty) |
c906108c | 970 | { |
1854bb21 SC |
971 | /* Make sure the curses mode is enabled. */ |
972 | tui_enable (); | |
63a33118 | 973 | if (arg != NULL) |
c906108c SS |
974 | { |
975 | int ts; | |
976 | ||
977 | ts = atoi (arg); | |
7806cea7 TT |
978 | if (ts <= 0) |
979 | warning (_("Tab widths greater than 0 must be specified.")); | |
980 | else | |
cb86fcc1 | 981 | { |
7806cea7 TT |
982 | internal_tab_width = ts; |
983 | tui_tab_width = ts; | |
984 | ||
985 | update_tab_width (); | |
cb86fcc1 | 986 | } |
c906108c | 987 | } |
6ba8e26f | 988 | } |
c906108c SS |
989 | |
990 | ||
1cc6d956 | 991 | /* Set the height of the specified window. */ |
c906108c | 992 | static void |
4dde7b34 | 993 | tui_set_win_height_command (const char *arg, int from_tty) |
c906108c | 994 | { |
1854bb21 SC |
995 | /* Make sure the curses mode is enabled. */ |
996 | tui_enable (); | |
63a33118 | 997 | if (arg != NULL) |
c906108c | 998 | { |
f71c8822 TT |
999 | std::string copy = arg; |
1000 | char *buf = ©[0]; | |
6ba8e26f | 1001 | char *buf_ptr = buf; |
e65b5245 | 1002 | char *wname = NULL; |
6ba8e26f | 1003 | int new_height, i; |
5b6fe301 | 1004 | struct tui_win_info *win_info; |
c906108c | 1005 | |
6ba8e26f AC |
1006 | wname = buf_ptr; |
1007 | buf_ptr = strchr (buf_ptr, ' '); | |
63a33118 | 1008 | if (buf_ptr != NULL) |
c906108c | 1009 | { |
6ba8e26f | 1010 | *buf_ptr = (char) 0; |
c906108c | 1011 | |
ef5eab5a | 1012 | /* Validate the window name. */ |
c906108c | 1013 | for (i = 0; i < strlen (wname); i++) |
6dce28e4 | 1014 | wname[i] = tolower (wname[i]); |
6d012f14 | 1015 | win_info = tui_partial_win_by_name (wname); |
c906108c | 1016 | |
cb2ce893 | 1017 | if (win_info == NULL || !win_info->is_visible) |
8a3fe4f8 AC |
1018 | warning (_("Invalid window specified. \n\ |
1019 | The window name specified must be valid and visible.\n")); | |
c906108c SS |
1020 | else |
1021 | { | |
1cc6d956 | 1022 | /* Process the size. */ |
6ba8e26f | 1023 | while (*(++buf_ptr) == ' ') |
c906108c SS |
1024 | ; |
1025 | ||
6ba8e26f | 1026 | if (*buf_ptr != (char) 0) |
c906108c SS |
1027 | { |
1028 | int negate = FALSE; | |
6ba8e26f AC |
1029 | int fixed_size = TRUE; |
1030 | int input_no;; | |
c906108c | 1031 | |
6ba8e26f | 1032 | if (*buf_ptr == '+' || *buf_ptr == '-') |
c906108c | 1033 | { |
6ba8e26f | 1034 | if (*buf_ptr == '-') |
c906108c | 1035 | negate = TRUE; |
6ba8e26f AC |
1036 | fixed_size = FALSE; |
1037 | buf_ptr++; | |
c906108c | 1038 | } |
6ba8e26f AC |
1039 | input_no = atoi (buf_ptr); |
1040 | if (input_no > 0) | |
c906108c SS |
1041 | { |
1042 | if (negate) | |
6ba8e26f AC |
1043 | input_no *= (-1); |
1044 | if (fixed_size) | |
1045 | new_height = input_no; | |
c906108c | 1046 | else |
cb2ce893 | 1047 | new_height = win_info->height + input_no; |
ef5eab5a MS |
1048 | |
1049 | /* Now change the window's height, and adjust | |
1050 | all other windows around it. */ | |
6ba8e26f AC |
1051 | if (tui_adjust_win_heights (win_info, |
1052 | new_height) == TUI_FAILURE) | |
8a3fe4f8 | 1053 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1054 | WIN_HEIGHT_USAGE); |
1055 | else | |
3e752b04 | 1056 | tui_update_gdb_sizes (); |
c906108c SS |
1057 | } |
1058 | else | |
8a3fe4f8 | 1059 | warning (_("Invalid window height specified.\n%s"), |
c906108c SS |
1060 | WIN_HEIGHT_USAGE); |
1061 | } | |
1062 | } | |
1063 | } | |
1064 | else | |
1065 | printf_filtered (WIN_HEIGHT_USAGE); | |
c906108c SS |
1066 | } |
1067 | else | |
1068 | printf_filtered (WIN_HEIGHT_USAGE); | |
6ba8e26f | 1069 | } |
c906108c | 1070 | |
6ba8e26f | 1071 | /* Function to adjust all window heights around the primary. */ |
22940a24 | 1072 | static enum tui_status |
08ef48c5 MS |
1073 | tui_adjust_win_heights (struct tui_win_info *primary_win_info, |
1074 | int new_height) | |
c906108c | 1075 | { |
22940a24 | 1076 | enum tui_status status = TUI_FAILURE; |
c906108c | 1077 | |
6ba8e26f | 1078 | if (new_height_ok (primary_win_info, new_height)) |
c906108c SS |
1079 | { |
1080 | status = TUI_SUCCESS; | |
cb2ce893 | 1081 | if (new_height != primary_win_info->height) |
c906108c | 1082 | { |
bc712bbf | 1083 | int diff; |
5b6fe301 | 1084 | struct tui_win_info *win_info; |
3add462f | 1085 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
6ba8e26f | 1086 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1087 | |
cb2ce893 | 1088 | diff = (new_height - primary_win_info->height) * (-1); |
e5908723 MS |
1089 | if (cur_layout == SRC_COMMAND |
1090 | || cur_layout == DISASSEM_COMMAND) | |
c906108c | 1091 | { |
5b6fe301 | 1092 | struct tui_win_info *src_win_info; |
c906108c | 1093 | |
6ba8e26f | 1094 | make_invisible_and_set_new_height (primary_win_info, new_height); |
cb2ce893 | 1095 | if (primary_win_info->type == CMD_WIN) |
c906108c | 1096 | { |
b4eb2452 | 1097 | win_info = tui_source_windows ()[0]; |
6ba8e26f | 1098 | src_win_info = win_info; |
c906108c SS |
1099 | } |
1100 | else | |
1101 | { | |
6d012f14 | 1102 | win_info = tui_win_list[CMD_WIN]; |
6ba8e26f | 1103 | src_win_info = primary_win_info; |
c906108c | 1104 | } |
6ba8e26f | 1105 | make_invisible_and_set_new_height (win_info, |
cb2ce893 TT |
1106 | win_info->height + diff); |
1107 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; | |
5fcee43a TT |
1108 | win_info->make_visible_with_new_height (); |
1109 | primary_win_info->make_visible_with_new_height (); | |
7908abbf | 1110 | if ((src_win_info->type == SRC_WIN |
53e7cdba TT |
1111 | || src_win_info->type == DISASSEM_WIN)) |
1112 | { | |
1113 | tui_source_window_base *src_base | |
1114 | = (tui_source_window_base *) src_win_info; | |
1115 | if (src_base->content.empty ()) | |
caf0bc4e | 1116 | tui_erase_source_content (src_base); |
53e7cdba | 1117 | } |
c906108c SS |
1118 | } |
1119 | else | |
1120 | { | |
6ba8e26f | 1121 | struct tui_win_info *first_win; |
7908abbf TT |
1122 | struct tui_source_window_base *second_win; |
1123 | tui_source_window_base *src1; | |
c906108c | 1124 | |
6ba8e26f | 1125 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1126 | { |
7908abbf TT |
1127 | src1 = TUI_SRC_WIN; |
1128 | first_win = src1; | |
6ba8e26f | 1129 | second_win = TUI_DISASM_WIN; |
c906108c SS |
1130 | } |
1131 | else | |
1132 | { | |
7908abbf | 1133 | src1 = nullptr; |
6ba8e26f | 1134 | first_win = TUI_DATA_WIN; |
b4eb2452 | 1135 | second_win = tui_source_windows ()[0]; |
c906108c | 1136 | } |
6ba8e26f | 1137 | if (primary_win_info == TUI_CMD_WIN) |
ef5eab5a MS |
1138 | { /* Split the change in height accross the 1st & 2nd |
1139 | windows, adjusting them as well. */ | |
1140 | /* Subtract the locator. */ | |
1141 | int first_split_diff = diff / 2; | |
6ba8e26f | 1142 | int second_split_diff = first_split_diff; |
c906108c SS |
1143 | |
1144 | if (diff % 2) | |
1145 | { | |
cb2ce893 TT |
1146 | if (first_win->height > |
1147 | second_win->height) | |
c906108c | 1148 | if (diff < 0) |
6ba8e26f | 1149 | first_split_diff--; |
c906108c | 1150 | else |
6ba8e26f | 1151 | first_split_diff++; |
c906108c SS |
1152 | else |
1153 | { | |
1154 | if (diff < 0) | |
6ba8e26f | 1155 | second_split_diff--; |
c906108c | 1156 | else |
6ba8e26f | 1157 | second_split_diff++; |
c906108c SS |
1158 | } |
1159 | } | |
1cc6d956 MS |
1160 | /* Make sure that the minimum hieghts are |
1161 | honored. */ | |
cb2ce893 | 1162 | while ((first_win->height + first_split_diff) < 3) |
c906108c | 1163 | { |
6ba8e26f AC |
1164 | first_split_diff++; |
1165 | second_split_diff--; | |
c906108c | 1166 | } |
cb2ce893 | 1167 | while ((second_win->height + second_split_diff) < 3) |
c906108c | 1168 | { |
6ba8e26f AC |
1169 | second_split_diff++; |
1170 | first_split_diff--; | |
c906108c | 1171 | } |
6ba8e26f AC |
1172 | make_invisible_and_set_new_height ( |
1173 | first_win, | |
cb2ce893 TT |
1174 | first_win->height + first_split_diff); |
1175 | second_win->origin.y = first_win->height - 1; | |
9a2b4c1b | 1176 | make_invisible_and_set_new_height (second_win, |
cb2ce893 | 1177 | second_win->height |
9a2b4c1b | 1178 | + second_split_diff); |
cb2ce893 | 1179 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; |
6ba8e26f | 1180 | make_invisible_and_set_new_height (TUI_CMD_WIN, new_height); |
c906108c SS |
1181 | } |
1182 | else | |
1183 | { | |
cb2ce893 | 1184 | if ((TUI_CMD_WIN->height + diff) < 1) |
ef5eab5a MS |
1185 | { /* If there is no way to increase the command |
1186 | window take real estate from the 1st or 2nd | |
1187 | window. */ | |
cb2ce893 | 1188 | if ((TUI_CMD_WIN->height + diff) < 1) |
c906108c SS |
1189 | { |
1190 | int i; | |
1c5313c5 | 1191 | |
cb2ce893 | 1192 | for (i = TUI_CMD_WIN->height + diff; |
c906108c | 1193 | (i < 1); i++) |
6ba8e26f | 1194 | if (primary_win_info == first_win) |
cb2ce893 | 1195 | second_win->height--; |
c906108c | 1196 | else |
cb2ce893 | 1197 | first_win->height--; |
c906108c SS |
1198 | } |
1199 | } | |
6ba8e26f AC |
1200 | if (primary_win_info == first_win) |
1201 | make_invisible_and_set_new_height (first_win, new_height); | |
c906108c | 1202 | else |
6ba8e26f AC |
1203 | make_invisible_and_set_new_height ( |
1204 | first_win, | |
cb2ce893 TT |
1205 | first_win->height); |
1206 | second_win->origin.y = first_win->height - 1; | |
6ba8e26f AC |
1207 | if (primary_win_info == second_win) |
1208 | make_invisible_and_set_new_height (second_win, new_height); | |
c906108c | 1209 | else |
6ba8e26f | 1210 | make_invisible_and_set_new_height ( |
cb2ce893 TT |
1211 | second_win, second_win->height); |
1212 | TUI_CMD_WIN->origin.y = locator->origin.y + 1; | |
1213 | if ((TUI_CMD_WIN->height + diff) < 1) | |
6ba8e26f | 1214 | make_invisible_and_set_new_height (TUI_CMD_WIN, 1); |
c906108c | 1215 | else |
9a2b4c1b | 1216 | make_invisible_and_set_new_height (TUI_CMD_WIN, |
cb2ce893 | 1217 | TUI_CMD_WIN->height + diff); |
c906108c | 1218 | } |
5fcee43a TT |
1219 | TUI_CMD_WIN->make_visible_with_new_height (); |
1220 | second_win->make_visible_with_new_height (); | |
1221 | first_win->make_visible_with_new_height (); | |
53e7cdba | 1222 | if (src1 != nullptr && src1->content.empty ()) |
caf0bc4e | 1223 | tui_erase_source_content (src1); |
53e7cdba | 1224 | if (second_win->content.empty ()) |
caf0bc4e | 1225 | tui_erase_source_content (second_win); |
c906108c SS |
1226 | } |
1227 | } | |
1228 | } | |
1229 | ||
1230 | return status; | |
6ba8e26f | 1231 | } |
c906108c SS |
1232 | |
1233 | ||
3f02ce1e TT |
1234 | /* See tui-data.h. */ |
1235 | ||
1236 | void | |
1237 | tui_source_window_base::set_new_height (int height) | |
1238 | { | |
1239 | tui_make_invisible (execution_info); | |
1240 | execution_info->height = height; | |
cb2ce893 | 1241 | execution_info->origin.y = origin.y; |
3f02ce1e TT |
1242 | if (height > 1) |
1243 | execution_info->viewport_height = height - 1; | |
1244 | else | |
1245 | execution_info->viewport_height = height; | |
1246 | execution_info->viewport_height--; | |
1247 | ||
1248 | if (has_locator ()) | |
1249 | { | |
3add462f | 1250 | tui_locator_window *gen_win_info = tui_locator_win_info_ptr (); |
3f02ce1e | 1251 | tui_make_invisible (gen_win_info); |
cb2ce893 | 1252 | gen_win_info->origin.y = origin.y + height; |
3f02ce1e TT |
1253 | } |
1254 | } | |
1255 | ||
1256 | /* See tui-data.h. */ | |
1257 | ||
1258 | void | |
1259 | tui_data_window::set_new_height (int height) | |
1260 | { | |
1261 | /* Delete all data item windows. */ | |
21e1c91e | 1262 | for (auto &&win : regs_content) |
3f02ce1e | 1263 | { |
21e1c91e TT |
1264 | tui_delete_win (win->handle); |
1265 | win->handle = NULL; | |
3f02ce1e TT |
1266 | } |
1267 | } | |
1268 | ||
6658b1bf | 1269 | /* Function make the target window (and auxiliary windows associated |
1cc6d956 MS |
1270 | with the targer) invisible, and set the new height and |
1271 | location. */ | |
c906108c | 1272 | static void |
08ef48c5 MS |
1273 | make_invisible_and_set_new_height (struct tui_win_info *win_info, |
1274 | int height) | |
c906108c | 1275 | { |
cb2ce893 TT |
1276 | tui_make_invisible (win_info); |
1277 | win_info->height = height; | |
c906108c | 1278 | if (height > 1) |
cb2ce893 | 1279 | win_info->viewport_height = height - 1; |
c906108c | 1280 | else |
cb2ce893 | 1281 | win_info->viewport_height = height; |
6d012f14 | 1282 | if (win_info != TUI_CMD_WIN) |
cb2ce893 | 1283 | win_info->viewport_height--; |
c906108c | 1284 | |
6658b1bf | 1285 | /* Now deal with the auxiliary windows associated with win_info. */ |
3f02ce1e | 1286 | win_info->set_new_height (height); |
bc712bbf | 1287 | } |
c906108c SS |
1288 | |
1289 | ||
5fcee43a TT |
1290 | /* See tui-data.h. */ |
1291 | ||
1292 | void | |
1293 | tui_win_info::make_visible_with_new_height () | |
c906108c | 1294 | { |
5fcee43a TT |
1295 | make_visible (true); |
1296 | tui_check_and_display_highlight_if_needed (this); | |
1297 | do_make_visible_with_new_height (); | |
1298 | } | |
1299 | ||
1300 | /* See tui-data.h. */ | |
c906108c | 1301 | |
5fcee43a TT |
1302 | void |
1303 | tui_source_window_base::do_make_visible_with_new_height () | |
1304 | { | |
5fcee43a | 1305 | tui_make_visible (execution_info); |
53e7cdba | 1306 | if (!content.empty ()) |
c906108c | 1307 | { |
5fcee43a TT |
1308 | struct tui_line_or_address line_or_addr; |
1309 | struct symtab_and_line cursal | |
1310 | = get_current_source_symtab_and_line (); | |
1311 | ||
1312 | line_or_addr = start_line_or_addr; | |
5fcee43a TT |
1313 | tui_update_source_window (this, gdbarch, |
1314 | cursal.symtab, line_or_addr, TRUE); | |
1315 | } | |
1316 | else if (deprecated_safe_get_selected_frame () != NULL) | |
1317 | { | |
1318 | struct tui_line_or_address line; | |
1319 | struct symtab_and_line cursal | |
1320 | = get_current_source_symtab_and_line (); | |
1321 | struct frame_info *frame = deprecated_safe_get_selected_frame (); | |
1322 | struct gdbarch *gdbarch = get_frame_arch (frame); | |
1323 | ||
1324 | struct symtab *s = find_pc_line_symtab (get_frame_pc (frame)); | |
1325 | if (type == SRC_WIN) | |
c906108c | 1326 | { |
5fcee43a TT |
1327 | line.loa = LOA_LINE; |
1328 | line.u.line_no = cursal.line; | |
c906108c | 1329 | } |
5fcee43a | 1330 | else |
c906108c | 1331 | { |
5fcee43a TT |
1332 | line.loa = LOA_ADDRESS; |
1333 | find_line_pc (s, cursal.line, &line.u.addr); | |
c906108c | 1334 | } |
5fcee43a TT |
1335 | tui_update_source_window (this, gdbarch, s, line, TRUE); |
1336 | } | |
1337 | if (has_locator ()) | |
1338 | { | |
1339 | tui_make_visible (tui_locator_win_info_ptr ()); | |
1340 | tui_show_locator_content (); | |
c906108c | 1341 | } |
6ba8e26f | 1342 | } |
c906108c | 1343 | |
5fcee43a TT |
1344 | /* See tui-data.h. */ |
1345 | ||
1346 | void | |
1347 | tui_data_window::do_make_visible_with_new_height () | |
1348 | { | |
50daf268 | 1349 | display_all_data (); |
5fcee43a TT |
1350 | } |
1351 | ||
1352 | /* See tui-data.h. */ | |
1353 | ||
1354 | void | |
1355 | tui_cmd_window::do_make_visible_with_new_height () | |
1356 | { | |
1357 | #ifdef HAVE_WRESIZE | |
1358 | wresize (handle, height, width); | |
1359 | #endif | |
1360 | mvwin (handle, origin.y, origin.x); | |
1361 | wmove (handle, 0, 0); | |
1362 | } | |
c906108c | 1363 | |
8903bd8a TT |
1364 | /* See tui-data.h. */ |
1365 | ||
1366 | int | |
1367 | tui_win_info::max_height () const | |
1368 | { | |
1369 | return tui_term_height () - 2; | |
1370 | } | |
1371 | ||
1372 | /* See tui-data.h. */ | |
1373 | ||
1374 | int | |
1375 | tui_cmd_window::max_height () const | |
1376 | { | |
1377 | return tui_term_height () - 4; | |
1378 | } | |
1379 | ||
c906108c | 1380 | static int |
08ef48c5 MS |
1381 | new_height_ok (struct tui_win_info *primary_win_info, |
1382 | int new_height) | |
c906108c | 1383 | { |
6ba8e26f | 1384 | int ok = (new_height < tui_term_height ()); |
c906108c SS |
1385 | |
1386 | if (ok) | |
1387 | { | |
bc712bbf | 1388 | int diff; |
6d012f14 | 1389 | enum tui_layout_type cur_layout = tui_current_layout (); |
c906108c | 1390 | |
cb2ce893 | 1391 | diff = (new_height - primary_win_info->height) * (-1); |
6d012f14 | 1392 | if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND) |
c906108c | 1393 | { |
8903bd8a TT |
1394 | ok = (new_height <= primary_win_info->max_height () |
1395 | && new_height >= MIN_CMD_WIN_HEIGHT); | |
c906108c | 1396 | if (ok) |
1cc6d956 | 1397 | { /* Check the total height. */ |
5b6fe301 | 1398 | struct tui_win_info *win_info; |
c906108c | 1399 | |
6ba8e26f | 1400 | if (primary_win_info == TUI_CMD_WIN) |
b4eb2452 | 1401 | win_info = tui_source_windows ()[0]; |
c906108c | 1402 | else |
6d012f14 | 1403 | win_info = TUI_CMD_WIN; |
6ba8e26f | 1404 | ok = ((new_height + |
cb2ce893 | 1405 | (win_info->height + diff)) <= tui_term_height ()); |
c906108c SS |
1406 | } |
1407 | } | |
1408 | else | |
1409 | { | |
6ba8e26f AC |
1410 | int cur_total_height, total_height, min_height = 0; |
1411 | struct tui_win_info *first_win; | |
1412 | struct tui_win_info *second_win; | |
c906108c | 1413 | |
6d012f14 | 1414 | if (cur_layout == SRC_DISASSEM_COMMAND) |
c906108c | 1415 | { |
6ba8e26f AC |
1416 | first_win = TUI_SRC_WIN; |
1417 | second_win = TUI_DISASM_WIN; | |
c906108c SS |
1418 | } |
1419 | else | |
1420 | { | |
6ba8e26f | 1421 | first_win = TUI_DATA_WIN; |
b4eb2452 | 1422 | second_win = tui_source_windows ()[0]; |
c906108c | 1423 | } |
ef5eab5a MS |
1424 | /* We could simply add all the heights to obtain the same |
1425 | result but below is more explicit since we subtract 1 for | |
1426 | the line that the first and second windows share, and add | |
1427 | one for the locator. */ | |
6ba8e26f | 1428 | total_height = cur_total_height = |
cb2ce893 TT |
1429 | (first_win->height + second_win->height - 1) |
1430 | + TUI_CMD_WIN->height + 1; /* Locator. */ | |
6ba8e26f | 1431 | if (primary_win_info == TUI_CMD_WIN) |
c906108c | 1432 | { |
1cc6d956 | 1433 | /* Locator included since first & second win share a line. */ |
cb2ce893 TT |
1434 | ok = ((first_win->height + |
1435 | second_win->height + diff) >= | |
e5908723 MS |
1436 | (MIN_WIN_HEIGHT * 2) |
1437 | && new_height >= MIN_CMD_WIN_HEIGHT); | |
c906108c SS |
1438 | if (ok) |
1439 | { | |
e5908723 | 1440 | total_height = new_height + |
cb2ce893 TT |
1441 | (first_win->height + |
1442 | second_win->height + diff); | |
6ba8e26f | 1443 | min_height = MIN_CMD_WIN_HEIGHT; |
c906108c SS |
1444 | } |
1445 | } | |
1446 | else | |
1447 | { | |
6ba8e26f | 1448 | min_height = MIN_WIN_HEIGHT; |
ef5eab5a MS |
1449 | |
1450 | /* First see if we can increase/decrease the command | |
1451 | window. And make sure that the command window is at | |
1452 | least 1 line. */ | |
cb2ce893 | 1453 | ok = ((TUI_CMD_WIN->height + diff) > 0); |
c906108c | 1454 | if (!ok) |
ef5eab5a MS |
1455 | { /* Looks like we have to increase/decrease one of |
1456 | the other windows. */ | |
6ba8e26f | 1457 | if (primary_win_info == first_win) |
cb2ce893 | 1458 | ok = (second_win->height + diff) >= min_height; |
c906108c | 1459 | else |
cb2ce893 | 1460 | ok = (first_win->height + diff) >= min_height; |
c906108c SS |
1461 | } |
1462 | if (ok) | |
1463 | { | |
6ba8e26f AC |
1464 | if (primary_win_info == first_win) |
1465 | total_height = new_height + | |
cb2ce893 TT |
1466 | second_win->height + |
1467 | TUI_CMD_WIN->height + diff; | |
c906108c | 1468 | else |
6ba8e26f | 1469 | total_height = new_height + |
cb2ce893 TT |
1470 | first_win->height + |
1471 | TUI_CMD_WIN->height + diff; | |
c906108c SS |
1472 | } |
1473 | } | |
ef5eab5a MS |
1474 | /* Now make sure that the proposed total height doesn't |
1475 | exceed the old total height. */ | |
c906108c | 1476 | if (ok) |
e5908723 MS |
1477 | ok = (new_height >= min_height |
1478 | && total_height <= cur_total_height); | |
c906108c SS |
1479 | } |
1480 | } | |
1481 | ||
1482 | return ok; | |
6ba8e26f | 1483 | } |
c906108c SS |
1484 | |
1485 | ||
c906108c | 1486 | static void |
0b39b52e | 1487 | parse_scrolling_args (const char *arg, |
08ef48c5 | 1488 | struct tui_win_info **win_to_scroll, |
6ba8e26f | 1489 | int *num_to_scroll) |
c906108c | 1490 | { |
6ba8e26f AC |
1491 | if (num_to_scroll) |
1492 | *num_to_scroll = 0; | |
1493 | *win_to_scroll = tui_win_with_focus (); | |
c906108c | 1494 | |
ef5eab5a MS |
1495 | /* First set up the default window to scroll, in case there is no |
1496 | window name arg. */ | |
63a33118 | 1497 | if (arg != NULL) |
c906108c | 1498 | { |
f71c8822 | 1499 | char *buf_ptr; |
c906108c | 1500 | |
1cc6d956 | 1501 | /* Process the number of lines to scroll. */ |
f71c8822 TT |
1502 | std::string copy = arg; |
1503 | buf_ptr = ©[0]; | |
6ba8e26f | 1504 | if (isdigit (*buf_ptr)) |
c906108c | 1505 | { |
6ba8e26f | 1506 | char *num_str; |
c906108c | 1507 | |
6ba8e26f AC |
1508 | num_str = buf_ptr; |
1509 | buf_ptr = strchr (buf_ptr, ' '); | |
63a33118 | 1510 | if (buf_ptr != NULL) |
c906108c | 1511 | { |
6ba8e26f AC |
1512 | *buf_ptr = (char) 0; |
1513 | if (num_to_scroll) | |
1514 | *num_to_scroll = atoi (num_str); | |
1515 | buf_ptr++; | |
c906108c | 1516 | } |
6ba8e26f AC |
1517 | else if (num_to_scroll) |
1518 | *num_to_scroll = atoi (num_str); | |
c906108c SS |
1519 | } |
1520 | ||
1cc6d956 | 1521 | /* Process the window name if one is specified. */ |
63a33118 | 1522 | if (buf_ptr != NULL) |
c906108c | 1523 | { |
a121b7c1 | 1524 | const char *wname; |
c906108c | 1525 | |
6ba8e26f AC |
1526 | if (*buf_ptr == ' ') |
1527 | while (*(++buf_ptr) == ' ') | |
c906108c SS |
1528 | ; |
1529 | ||
6ba8e26f | 1530 | if (*buf_ptr != (char) 0) |
c709a7c2 | 1531 | { |
c709a7c2 | 1532 | /* Validate the window name. */ |
a121b7c1 PA |
1533 | for (char *p = buf_ptr; *p != '\0'; p++) |
1534 | *p = tolower (*p); | |
1535 | ||
1536 | wname = buf_ptr; | |
c709a7c2 | 1537 | } |
a4b99e53 SC |
1538 | else |
1539 | wname = "?"; | |
1540 | ||
6ba8e26f | 1541 | *win_to_scroll = tui_partial_win_by_name (wname); |
c906108c | 1542 | |
cafb3438 | 1543 | if (*win_to_scroll == NULL |
cb2ce893 | 1544 | || !(*win_to_scroll)->is_visible) |
ec502284 | 1545 | error (_("Invalid window specified. \n\ |
8a3fe4f8 | 1546 | The window name specified must be valid and visible.\n")); |
6ba8e26f | 1547 | else if (*win_to_scroll == TUI_CMD_WIN) |
b4eb2452 | 1548 | *win_to_scroll = tui_source_windows ()[0]; |
c906108c | 1549 | } |
c906108c | 1550 | } |
6ba8e26f | 1551 | } |
7806cea7 TT |
1552 | |
1553 | /* Function to initialize gdb commands, for tui window | |
1554 | manipulation. */ | |
1555 | ||
1556 | void | |
1557 | _initialize_tui_win (void) | |
1558 | { | |
1559 | static struct cmd_list_element *tui_setlist; | |
1560 | static struct cmd_list_element *tui_showlist; | |
1561 | struct cmd_list_element *cmd; | |
1562 | ||
1563 | /* Define the classes of commands. | |
1564 | They will appear in the help list in the reverse of this order. */ | |
1565 | add_prefix_cmd ("tui", class_tui, set_tui_cmd, | |
1566 | _("TUI configuration variables"), | |
1567 | &tui_setlist, "set tui ", | |
1568 | 0 /* allow-unknown */, &setlist); | |
1569 | add_prefix_cmd ("tui", class_tui, show_tui_cmd, | |
1570 | _("TUI configuration variables"), | |
1571 | &tui_showlist, "show tui ", | |
1572 | 0 /* allow-unknown */, &showlist); | |
1573 | ||
1574 | add_com ("refresh", class_tui, tui_refresh_all_command, | |
89549d7f | 1575 | _("Refresh the terminal display.")); |
7806cea7 TT |
1576 | |
1577 | cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\ | |
1578 | Set the width (in characters) of tab stops.\n\ | |
89549d7f | 1579 | Usage: tabset N")); |
7806cea7 TT |
1580 | deprecate_cmd (cmd, "set tui tab-width"); |
1581 | ||
1582 | cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\ | |
1583 | Set or modify the height of a specified window.\n" | |
1584 | WIN_HEIGHT_USAGE | |
1585 | "Window names are:\n\ | |
89549d7f TT |
1586 | src : the source window\n\ |
1587 | cmd : the command window\n\ | |
1588 | asm : the disassembly window\n\ | |
1589 | regs : the register display")); | |
7806cea7 TT |
1590 | add_com_alias ("wh", "winheight", class_tui, 0); |
1591 | set_cmd_completer (cmd, winheight_completer); | |
1592 | add_info ("win", tui_all_windows_info, | |
89549d7f | 1593 | _("List of all displayed windows.")); |
7806cea7 TT |
1594 | cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\ |
1595 | Set focus to named window or next/prev window.\n" | |
1596 | FOCUS_USAGE | |
1597 | "Valid Window names are:\n\ | |
89549d7f TT |
1598 | src : the source window\n\ |
1599 | asm : the disassembly window\n\ | |
1600 | regs : the register display\n\ | |
1601 | cmd : the command window")); | |
7806cea7 TT |
1602 | add_com_alias ("fs", "focus", class_tui, 0); |
1603 | set_cmd_completer (cmd, focus_completer); | |
1604 | add_com ("+", class_tui, tui_scroll_forward_command, _("\ | |
1605 | Scroll window forward.\n\ | |
89549d7f | 1606 | Usage: + [WIN] [N]")); |
7806cea7 TT |
1607 | add_com ("-", class_tui, tui_scroll_backward_command, _("\ |
1608 | Scroll window backward.\n\ | |
89549d7f | 1609 | Usage: - [WIN] [N]")); |
7806cea7 TT |
1610 | add_com ("<", class_tui, tui_scroll_left_command, _("\ |
1611 | Scroll window text to the left.\n\ | |
89549d7f | 1612 | Usage: < [WIN] [N]")); |
7806cea7 TT |
1613 | add_com (">", class_tui, tui_scroll_right_command, _("\ |
1614 | Scroll window text to the right.\n\ | |
89549d7f | 1615 | Usage: > [WIN] [N]")); |
7806cea7 TT |
1616 | |
1617 | /* Define the tui control variables. */ | |
1618 | add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums, | |
1619 | &tui_border_kind, _("\ | |
1620 | Set the kind of border for TUI windows."), _("\ | |
1621 | Show the kind of border for TUI windows."), _("\ | |
1622 | This variable controls the border of TUI windows:\n\ | |
89549d7f TT |
1623 | space use a white space\n\ |
1624 | ascii use ascii characters + - | for the border\n\ | |
1625 | acs use the Alternate Character Set"), | |
7806cea7 TT |
1626 | tui_set_var_cmd, |
1627 | show_tui_border_kind, | |
1628 | &tui_setlist, &tui_showlist); | |
1629 | ||
1630 | add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums, | |
1631 | &tui_border_mode, _("\ | |
1632 | Set the attribute mode to use for the TUI window borders."), _("\ | |
1633 | Show the attribute mode to use for the TUI window borders."), _("\ | |
1634 | This variable controls the attributes to use for the window borders:\n\ | |
89549d7f TT |
1635 | normal normal display\n\ |
1636 | standout use highlight mode of terminal\n\ | |
1637 | reverse use reverse video mode\n\ | |
1638 | half use half bright\n\ | |
1639 | half-standout use half bright and standout mode\n\ | |
1640 | bold use extra bright or bold\n\ | |
1641 | bold-standout use extra bright or bold with standout mode"), | |
7806cea7 TT |
1642 | tui_set_var_cmd, |
1643 | show_tui_border_mode, | |
1644 | &tui_setlist, &tui_showlist); | |
1645 | ||
1646 | add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums, | |
1647 | &tui_active_border_mode, _("\ | |
1648 | Set the attribute mode to use for the active TUI window border."), _("\ | |
1649 | Show the attribute mode to use for the active TUI window border."), _("\ | |
1650 | This variable controls the attributes to use for the active window border:\n\ | |
89549d7f TT |
1651 | normal normal display\n\ |
1652 | standout use highlight mode of terminal\n\ | |
1653 | reverse use reverse video mode\n\ | |
1654 | half use half bright\n\ | |
1655 | half-standout use half bright and standout mode\n\ | |
1656 | bold use extra bright or bold\n\ | |
1657 | bold-standout use extra bright or bold with standout mode"), | |
7806cea7 TT |
1658 | tui_set_var_cmd, |
1659 | show_tui_active_border_mode, | |
1660 | &tui_setlist, &tui_showlist); | |
1661 | ||
1662 | add_setshow_zuinteger_cmd ("tab-width", no_class, | |
1663 | &internal_tab_width, _("\ | |
1664 | Set the tab width, in characters, for the TUI."), _("\ | |
1665 | Show the tab witdh, in characters, for the TUI"), _("\ | |
1666 | This variable controls how many spaces are used to display a tab character."), | |
1667 | tui_set_tab_width, tui_show_tab_width, | |
1668 | &tui_setlist, &tui_showlist); | |
1669 | } |