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