Introduce tui_win_info::make_visible_with_new_height
[deliverable/binutils-gdb.git] / gdb / tui / tui-win.c
1 /* TUI window generic functions.
2
3 Copyright (C) 1998-2019 Free Software Foundation, Inc.
4
5 Contributed by Hewlett-Packard Company.
6
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
11 the Free Software Foundation; either version 3 of the License, or
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
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
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 */
26
27 #include "defs.h"
28 #include "command.h"
29 #include "symtab.h"
30 #include "breakpoint.h"
31 #include "frame.h"
32 #include "cli/cli-cmds.h"
33 #include "top.h"
34 #include "source.h"
35 #include "event-loop.h"
36
37 #include "tui/tui.h"
38 #include "tui/tui-io.h"
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"
47 #include "tui/tui-win.h"
48
49 #include "gdb_curses.h"
50 #include <ctype.h>
51 #include "readline/readline.h"
52
53 #include <signal.h>
54
55 /*******************************
56 ** Static Local Decls
57 ********************************/
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);
62 static int new_height_ok (struct tui_win_info *, int);
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);
66 static void tui_all_windows_info (const char *, int);
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 *,
73 struct tui_win_info **,
74 int *);
75
76
77 /***************************************
78 ** DEFINITIONS
79 ***************************************/
80 #define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
81 #define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
82
83 /***************************************
84 ** PUBLIC FUNCTIONS
85 ***************************************/
86
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
106 /* Possible values for tui-border-kind variable. */
107 static const char *const tui_border_kind_enums[] = {
108 "space",
109 "ascii",
110 "acs",
111 NULL
112 };
113
114 /* Possible values for tui-border-mode and tui-active-border-mode. */
115 static const char *const tui_border_mode_enums[] = {
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";
202 static void
203 show_tui_active_border_mode (struct ui_file *file,
204 int from_tty,
205 struct cmd_list_element *c,
206 const char *value)
207 {
208 fprintf_filtered (file, _("\
209 The attribute mode to use for the active TUI window border is \"%s\".\n"),
210 value);
211 }
212
213 const char *tui_border_mode = "normal";
214 static void
215 show_tui_border_mode (struct ui_file *file,
216 int from_tty,
217 struct cmd_list_element *c,
218 const char *value)
219 {
220 fprintf_filtered (file, _("\
221 The attribute mode to use for the TUI window borders is \"%s\".\n"),
222 value);
223 }
224
225 const char *tui_border_kind = "acs";
226 static void
227 show_tui_border_kind (struct ui_file *file,
228 int from_tty,
229 struct cmd_list_element *c,
230 const char *value)
231 {
232 fprintf_filtered (file, _("The kind of border for TUI windows is \"%s\".\n"),
233 value);
234 }
235
236
237 /* Tui internal configuration variables. These variables are updated
238 by tui_update_variables to reflect the tui configuration
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
271 tui_update_variables (void)
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
316 static void
317 set_tui_cmd (const char *args, int from_tty)
318 {
319 }
320
321 static void
322 show_tui_cmd (const char *args, int from_tty)
323 {
324 }
325
326 static struct cmd_list_element *tuilist;
327
328 static void
329 tui_command (const char *args, int from_tty)
330 {
331 printf_unfiltered (_("\"tui\" must be followed by the name of a "
332 "tui command.\n"));
333 help_list (tuilist, "tui ", all_commands, gdb_stdout);
334 }
335
336 struct cmd_list_element **
337 tui_get_cmd_list (void)
338 {
339 if (tuilist == 0)
340 add_prefix_cmd ("tui", class_tui, tui_command,
341 _("Text User Interface commands."),
342 &tuilist, "tui ", 0, &cmdlist);
343 return &tuilist;
344 }
345
346 /* The set_func hook of "set tui ..." commands that affect the window
347 borders on the TUI display. */
348 void
349 tui_set_var_cmd (const char *null_args,
350 int from_tty, struct cmd_list_element *c)
351 {
352 if (tui_update_variables () && tui_active)
353 tui_rehighlight_all ();
354 }
355
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. */
360
361 static void
362 window_name_completer (completion_tracker &tracker,
363 int include_next_prev_p,
364 const char *text, const char *word)
365 {
366 std::vector<const char *> completion_name_vec;
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
375 || !tui_win_list[win_type]->is_visible)
376 continue;
377
378 completion_name = tui_win_list[win_type]->name ();
379 gdb_assert (completion_name != NULL);
380 completion_name_vec.push_back (completion_name);
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. */
387 if (completion_name_vec.empty ())
388 {
389 completion_name_vec.push_back (SRC_NAME);
390 completion_name_vec.push_back (CMD_NAME);
391 }
392
393 if (include_next_prev_p)
394 {
395 completion_name_vec.push_back ("next");
396 completion_name_vec.push_back ("prev");
397 }
398
399
400 completion_name_vec.push_back (NULL);
401 complete_on_enum (tracker, completion_name_vec.data (), text, word);
402 }
403
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
407 static void
408 focus_completer (struct cmd_list_element *ignore,
409 completion_tracker &tracker,
410 const char *text, const char *word)
411 {
412 window_name_completer (tracker, 1, text, word);
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
419 static void
420 winheight_completer (struct cmd_list_element *ignore,
421 completion_tracker &tracker,
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)
427 return;
428
429 window_name_completer (tracker, 0, text, word);
430 }
431
432 /* Update gdb's knowledge of the terminal size. */
433 void
434 tui_update_gdb_sizes (void)
435 {
436 int width, height;
437
438 if (tui_active)
439 {
440 width = TUI_CMD_WIN->width;
441 height = TUI_CMD_WIN->height;
442 }
443 else
444 {
445 width = tui_term_width ();
446 height = tui_term_height ();
447 }
448
449 set_screen_width_and_height (width, height);
450 }
451
452
453 /* Set the logical focus to win_info. */
454 void
455 tui_set_win_focus_to (struct tui_win_info *win_info)
456 {
457 if (win_info != NULL)
458 {
459 struct tui_win_info *win_with_focus = tui_win_with_focus ();
460
461 if (win_with_focus != NULL
462 && win_with_focus->type != CMD_WIN)
463 tui_unhighlight_win (win_with_focus);
464 tui_set_win_with_focus (win_info);
465 if (win_info->type != CMD_WIN)
466 tui_highlight_win (win_info);
467 }
468 }
469
470
471 void
472 tui_win_info::forward_scroll (int num_to_scroll)
473 {
474 if (num_to_scroll == 0)
475 num_to_scroll = height - 3;
476
477 do_scroll_vertical (num_to_scroll);
478 }
479
480 void
481 tui_win_info::backward_scroll (int num_to_scroll)
482 {
483 if (num_to_scroll == 0)
484 num_to_scroll = height - 3;
485
486 do_scroll_vertical (-num_to_scroll);
487 }
488
489
490 void
491 tui_win_info::left_scroll (int num_to_scroll)
492 {
493 if (num_to_scroll == 0)
494 num_to_scroll = 1;
495
496 do_scroll_horizontal (num_to_scroll);
497 }
498
499
500 void
501 tui_win_info::right_scroll (int num_to_scroll)
502 {
503 if (num_to_scroll == 0)
504 num_to_scroll = 1;
505
506 do_scroll_horizontal (-num_to_scroll);
507 }
508
509
510 /* See tui-data.h. */
511
512 void
513 tui_source_window_base::refresh_all ()
514 {
515 tui_show_source_content (this);
516 tui_check_and_display_highlight_if_needed (this);
517 tui_erase_exec_info_content (this);
518 tui_update_exec_info (this);
519 }
520
521 void
522 tui_refresh_all_win (void)
523 {
524 int type;
525
526 clearok (curscr, TRUE);
527 tui_refresh_all (tui_win_list);
528 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
529 {
530 if (tui_win_list[type] && tui_win_list[type]->is_visible)
531 tui_win_list[type]->refresh_all ();
532 }
533 tui_show_locator_content ();
534 }
535
536 void
537 tui_rehighlight_all (void)
538 {
539 int type;
540
541 for (type = SRC_WIN; type < MAX_MAJOR_WINDOWS; type++)
542 tui_check_and_display_highlight_if_needed (tui_win_list[type]);
543 }
544
545 /* Resize all the windows based on the terminal size. This function
546 gets called from within the readline sinwinch handler. */
547 void
548 tui_resize_all (void)
549 {
550 int height_diff, width_diff;
551 int screenheight, screenwidth;
552
553 rl_get_screen_size (&screenheight, &screenwidth);
554 width_diff = screenwidth - tui_term_width ();
555 height_diff = screenheight - tui_term_height ();
556 if (height_diff || width_diff)
557 {
558 enum tui_layout_type cur_layout = tui_current_layout ();
559 struct tui_win_info *win_with_focus = tui_win_with_focus ();
560 struct tui_win_info *first_win;
561 struct tui_win_info *second_win;
562 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
563 int win_type;
564 int new_height, split_diff, cmd_split_diff, num_wins_displayed = 2;
565
566 #ifdef HAVE_RESIZE_TERM
567 resize_term (screenheight, screenwidth);
568 #endif
569 /* Turn keypad off while we resize. */
570 if (win_with_focus != TUI_CMD_WIN)
571 keypad (TUI_CMD_WIN->handle, FALSE);
572 tui_update_gdb_sizes ();
573 tui_set_term_height_to (screenheight);
574 tui_set_term_width_to (screenwidth);
575 if (cur_layout == SRC_DISASSEM_COMMAND
576 || cur_layout == SRC_DATA_COMMAND
577 || cur_layout == DISASSEM_DATA_COMMAND)
578 num_wins_displayed++;
579 split_diff = height_diff / num_wins_displayed;
580 cmd_split_diff = split_diff;
581 if (height_diff % num_wins_displayed)
582 {
583 if (height_diff < 0)
584 cmd_split_diff--;
585 else
586 cmd_split_diff++;
587 }
588 /* Now adjust each window. */
589 /* erase + clearok are used instead of a straightforward clear as
590 AIX 5.3 does not define clear. */
591 erase ();
592 clearok (curscr, TRUE);
593 refresh ();
594 switch (cur_layout)
595 {
596 case SRC_COMMAND:
597 case DISASSEM_COMMAND:
598 first_win = tui_source_windows ()[0];
599 first_win->width += width_diff;
600 locator->width += width_diff;
601 /* Check for invalid heights. */
602 if (height_diff == 0)
603 new_height = first_win->height;
604 else if ((first_win->height + split_diff) >=
605 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
606 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
607 else if ((first_win->height + split_diff) <= 0)
608 new_height = MIN_WIN_HEIGHT;
609 else
610 new_height = first_win->height + split_diff;
611
612 locator->origin.y = new_height + 1;
613 make_invisible_and_set_new_height (first_win, new_height);
614 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
615 TUI_CMD_WIN->width += width_diff;
616 new_height = screenheight - TUI_CMD_WIN->origin.y;
617 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
618 first_win->make_visible_with_new_height ();
619 TUI_CMD_WIN->make_visible_with_new_height ();
620 if (first_win->content_size <= 0)
621 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
622 break;
623 default:
624 if (cur_layout == SRC_DISASSEM_COMMAND)
625 {
626 first_win = TUI_SRC_WIN;
627 first_win->width += width_diff;
628 second_win = TUI_DISASM_WIN;
629 second_win->width += width_diff;
630 }
631 else
632 {
633 first_win = TUI_DATA_WIN;
634 first_win->width += width_diff;
635 second_win = tui_source_windows ()[0];
636 second_win->width += width_diff;
637 }
638 /* Change the first window's height/width. */
639 /* Check for invalid heights. */
640 if (height_diff == 0)
641 new_height = first_win->height;
642 else if ((first_win->height +
643 second_win->height + (split_diff * 2)) >=
644 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
645 new_height = (screenheight - MIN_CMD_WIN_HEIGHT - 1) / 2;
646 else if ((first_win->height + split_diff) <= 0)
647 new_height = MIN_WIN_HEIGHT;
648 else
649 new_height = first_win->height + split_diff;
650 make_invisible_and_set_new_height (first_win, new_height);
651
652 locator->width += width_diff;
653
654 /* Change the second window's height/width. */
655 /* Check for invalid heights. */
656 if (height_diff == 0)
657 new_height = second_win->height;
658 else if ((first_win->height +
659 second_win->height + (split_diff * 2)) >=
660 (screenheight - MIN_CMD_WIN_HEIGHT - 1))
661 {
662 new_height = screenheight - MIN_CMD_WIN_HEIGHT - 1;
663 if (new_height % 2)
664 new_height = (new_height / 2) + 1;
665 else
666 new_height /= 2;
667 }
668 else if ((second_win->height + split_diff) <= 0)
669 new_height = MIN_WIN_HEIGHT;
670 else
671 new_height = second_win->height + split_diff;
672 second_win->origin.y = first_win->height - 1;
673 make_invisible_and_set_new_height (second_win, new_height);
674
675 /* Change the command window's height/width. */
676 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
677 make_invisible_and_set_new_height (TUI_CMD_WIN,
678 TUI_CMD_WIN->height
679 + cmd_split_diff);
680 first_win->make_visible_with_new_height ();
681 second_win->make_visible_with_new_height ();
682 TUI_CMD_WIN->make_visible_with_new_height ();
683 if (first_win->content_size <= 0)
684 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
685 if (second_win->content_size <= 0)
686 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
687 break;
688 }
689 /* Now remove all invisible windows, and their content so that
690 they get created again when called for with the new size. */
691 for (win_type = SRC_WIN; (win_type < MAX_MAJOR_WINDOWS); win_type++)
692 {
693 if (win_type != CMD_WIN
694 && (tui_win_list[win_type] != NULL)
695 && !tui_win_list[win_type]->is_visible)
696 {
697 delete tui_win_list[win_type];
698 tui_win_list[win_type] = NULL;
699 }
700 }
701 /* Turn keypad back on, unless focus is in the command
702 window. */
703 if (win_with_focus != TUI_CMD_WIN)
704 keypad (TUI_CMD_WIN->handle, TRUE);
705 }
706 }
707
708 #ifdef SIGWINCH
709 /* Token for use by TUI's asynchronous SIGWINCH handler. */
710 static struct async_signal_handler *tui_sigwinch_token;
711
712 /* TUI's SIGWINCH signal handler. */
713 static void
714 tui_sigwinch_handler (int signal)
715 {
716 mark_async_signal_handler (tui_sigwinch_token);
717 tui_set_win_resized_to (TRUE);
718 }
719
720 /* Callback for asynchronously resizing TUI following a SIGWINCH signal. */
721 static void
722 tui_async_resize_screen (gdb_client_data arg)
723 {
724 rl_resize_terminal ();
725
726 if (!tui_active)
727 {
728 int screen_height, screen_width;
729
730 rl_get_screen_size (&screen_height, &screen_width);
731 set_screen_width_and_height (screen_width, screen_height);
732
733 /* win_resized is left set so that the next call to tui_enable()
734 resizes the TUI windows. */
735 }
736 else
737 {
738 tui_set_win_resized_to (FALSE);
739 tui_resize_all ();
740 tui_refresh_all_win ();
741 tui_update_gdb_sizes ();
742 tui_redisplay_readline ();
743 }
744 }
745 #endif
746
747 /* Initialize TUI's SIGWINCH signal handler. Note that the handler is not
748 uninstalled when we exit TUI, so the handler should not assume that TUI is
749 always active. */
750 void
751 tui_initialize_win (void)
752 {
753 #ifdef SIGWINCH
754 tui_sigwinch_token
755 = create_async_signal_handler (tui_async_resize_screen, NULL);
756
757 {
758 #ifdef HAVE_SIGACTION
759 struct sigaction old_winch;
760
761 memset (&old_winch, 0, sizeof (old_winch));
762 old_winch.sa_handler = &tui_sigwinch_handler;
763 #ifdef SA_RESTART
764 old_winch.sa_flags = SA_RESTART;
765 #endif
766 sigaction (SIGWINCH, &old_winch, NULL);
767 #else
768 signal (SIGWINCH, &tui_sigwinch_handler);
769 #endif
770 }
771 #endif
772 }
773
774
775 /*************************
776 ** STATIC LOCAL FUNCTIONS
777 **************************/
778
779
780 static void
781 tui_scroll_forward_command (const char *arg, int from_tty)
782 {
783 int num_to_scroll = 1;
784 struct tui_win_info *win_to_scroll;
785
786 /* Make sure the curses mode is enabled. */
787 tui_enable ();
788 if (arg == NULL)
789 parse_scrolling_args (arg, &win_to_scroll, NULL);
790 else
791 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
792 win_to_scroll->forward_scroll (num_to_scroll);
793 }
794
795
796 static void
797 tui_scroll_backward_command (const char *arg, int from_tty)
798 {
799 int num_to_scroll = 1;
800 struct tui_win_info *win_to_scroll;
801
802 /* Make sure the curses mode is enabled. */
803 tui_enable ();
804 if (arg == NULL)
805 parse_scrolling_args (arg, &win_to_scroll, NULL);
806 else
807 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
808 win_to_scroll->backward_scroll (num_to_scroll);
809 }
810
811
812 static void
813 tui_scroll_left_command (const char *arg, int from_tty)
814 {
815 int num_to_scroll;
816 struct tui_win_info *win_to_scroll;
817
818 /* Make sure the curses mode is enabled. */
819 tui_enable ();
820 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
821 win_to_scroll->left_scroll (num_to_scroll);
822 }
823
824
825 static void
826 tui_scroll_right_command (const char *arg, int from_tty)
827 {
828 int num_to_scroll;
829 struct tui_win_info *win_to_scroll;
830
831 /* Make sure the curses mode is enabled. */
832 tui_enable ();
833 parse_scrolling_args (arg, &win_to_scroll, &num_to_scroll);
834 win_to_scroll->right_scroll (num_to_scroll);
835 }
836
837
838 /* Set focus to the window named by 'arg'. */
839 static void
840 tui_set_focus (const char *arg, int from_tty)
841 {
842 if (arg != NULL)
843 {
844 char *buf_ptr = xstrdup (arg);
845 int i;
846 struct tui_win_info *win_info = NULL;
847
848 for (i = 0; (i < strlen (buf_ptr)); i++)
849 buf_ptr[i] = tolower (arg[i]);
850
851 if (subset_compare (buf_ptr, "next"))
852 win_info = tui_next_win (tui_win_with_focus ());
853 else if (subset_compare (buf_ptr, "prev"))
854 win_info = tui_prev_win (tui_win_with_focus ());
855 else
856 win_info = tui_partial_win_by_name (buf_ptr);
857
858 if (win_info == NULL || !win_info->is_visible)
859 warning (_("Invalid window specified. \n\
860 The window name specified must be valid and visible.\n"));
861 else
862 {
863 tui_set_win_focus_to (win_info);
864 keypad (TUI_CMD_WIN->handle, (win_info != TUI_CMD_WIN));
865 }
866
867 if (TUI_DATA_WIN && TUI_DATA_WIN->is_visible)
868 TUI_DATA_WIN->refresh_all ();
869 xfree (buf_ptr);
870 printf_filtered (_("Focus set to %s window.\n"),
871 tui_win_with_focus ()->name ());
872 }
873 else
874 warning (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
875 }
876
877 static void
878 tui_set_focus_command (const char *arg, int from_tty)
879 {
880 /* Make sure the curses mode is enabled. */
881 tui_enable ();
882 tui_set_focus (arg, from_tty);
883 }
884
885
886 static void
887 tui_all_windows_info (const char *arg, int from_tty)
888 {
889 int type;
890 struct tui_win_info *win_with_focus = tui_win_with_focus ();
891
892 for (type = SRC_WIN; (type < MAX_MAJOR_WINDOWS); type++)
893 if (tui_win_list[type]
894 && tui_win_list[type]->is_visible)
895 {
896 if (win_with_focus == tui_win_list[type])
897 printf_filtered (" %s\t(%d lines) <has focus>\n",
898 tui_win_list[type]->name (),
899 tui_win_list[type]->height);
900 else
901 printf_filtered (" %s\t(%d lines)\n",
902 tui_win_list[type]->name (),
903 tui_win_list[type]->height);
904 }
905 }
906
907
908 static void
909 tui_refresh_all_command (const char *arg, int from_tty)
910 {
911 /* Make sure the curses mode is enabled. */
912 tui_enable ();
913
914 tui_refresh_all_win ();
915 }
916
917 /* The tab width that should be used by the TUI. */
918
919 unsigned int tui_tab_width = DEFAULT_TAB_LEN;
920
921 /* The tab width as set by the user. */
922
923 static unsigned int internal_tab_width = DEFAULT_TAB_LEN;
924
925 /* See tui-data.h. */
926
927 void
928 tui_source_window_base::update_tab_width ()
929 {
930 /* We don't really change the height of any windows, but
931 calling these 2 functions causes a complete regeneration
932 and redisplay of the window's contents, which will take
933 the new tab width into account. */
934 make_invisible_and_set_new_height (this, height);
935 make_visible_with_new_height ();
936 }
937
938 /* After the tab width is set, call this to update the relevant
939 windows. */
940
941 static void
942 update_tab_width ()
943 {
944 for (int win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++)
945 {
946 if (tui_win_list[win_type] != NULL
947 && tui_win_list[win_type]->is_visible)
948 tui_win_list[win_type]->update_tab_width ();
949 }
950 }
951
952 /* Callback for "set tui tab-width". */
953
954 static void
955 tui_set_tab_width (const char *ignore,
956 int from_tty, struct cmd_list_element *c)
957 {
958 if (internal_tab_width == 0)
959 {
960 internal_tab_width = tui_tab_width;
961 error (_("Tab width must not be 0"));
962 }
963
964 tui_tab_width = internal_tab_width;
965 update_tab_width ();
966 }
967
968 /* Callback for "show tui tab-width". */
969
970 static void
971 tui_show_tab_width (struct ui_file *file, int from_tty,
972 struct cmd_list_element *c, const char *value)
973 {
974 fprintf_filtered (gdb_stdout, _("TUI tab width is %s spaces.\n"), value);
975
976 }
977
978 /* Set the tab width of the specified window. */
979 static void
980 tui_set_tab_width_command (const char *arg, int from_tty)
981 {
982 /* Make sure the curses mode is enabled. */
983 tui_enable ();
984 if (arg != NULL)
985 {
986 int ts;
987
988 ts = atoi (arg);
989 if (ts <= 0)
990 warning (_("Tab widths greater than 0 must be specified."));
991 else
992 {
993 internal_tab_width = ts;
994 tui_tab_width = ts;
995
996 update_tab_width ();
997 }
998 }
999 }
1000
1001
1002 /* Set the height of the specified window. */
1003 static void
1004 tui_set_win_height (const char *arg, int from_tty)
1005 {
1006 /* Make sure the curses mode is enabled. */
1007 tui_enable ();
1008 if (arg != NULL)
1009 {
1010 std::string copy = arg;
1011 char *buf = &copy[0];
1012 char *buf_ptr = buf;
1013 char *wname = NULL;
1014 int new_height, i;
1015 struct tui_win_info *win_info;
1016
1017 wname = buf_ptr;
1018 buf_ptr = strchr (buf_ptr, ' ');
1019 if (buf_ptr != NULL)
1020 {
1021 *buf_ptr = (char) 0;
1022
1023 /* Validate the window name. */
1024 for (i = 0; i < strlen (wname); i++)
1025 wname[i] = tolower (wname[i]);
1026 win_info = tui_partial_win_by_name (wname);
1027
1028 if (win_info == NULL || !win_info->is_visible)
1029 warning (_("Invalid window specified. \n\
1030 The window name specified must be valid and visible.\n"));
1031 else
1032 {
1033 /* Process the size. */
1034 while (*(++buf_ptr) == ' ')
1035 ;
1036
1037 if (*buf_ptr != (char) 0)
1038 {
1039 int negate = FALSE;
1040 int fixed_size = TRUE;
1041 int input_no;;
1042
1043 if (*buf_ptr == '+' || *buf_ptr == '-')
1044 {
1045 if (*buf_ptr == '-')
1046 negate = TRUE;
1047 fixed_size = FALSE;
1048 buf_ptr++;
1049 }
1050 input_no = atoi (buf_ptr);
1051 if (input_no > 0)
1052 {
1053 if (negate)
1054 input_no *= (-1);
1055 if (fixed_size)
1056 new_height = input_no;
1057 else
1058 new_height = win_info->height + input_no;
1059
1060 /* Now change the window's height, and adjust
1061 all other windows around it. */
1062 if (tui_adjust_win_heights (win_info,
1063 new_height) == TUI_FAILURE)
1064 warning (_("Invalid window height specified.\n%s"),
1065 WIN_HEIGHT_USAGE);
1066 else
1067 tui_update_gdb_sizes ();
1068 }
1069 else
1070 warning (_("Invalid window height specified.\n%s"),
1071 WIN_HEIGHT_USAGE);
1072 }
1073 }
1074 }
1075 else
1076 printf_filtered (WIN_HEIGHT_USAGE);
1077 }
1078 else
1079 printf_filtered (WIN_HEIGHT_USAGE);
1080 }
1081
1082 /* Set the height of the specified window, with va_list. */
1083 static void
1084 tui_set_win_height_command (const char *arg, int from_tty)
1085 {
1086 /* Make sure the curses mode is enabled. */
1087 tui_enable ();
1088 tui_set_win_height (arg, from_tty);
1089 }
1090
1091 /* Function to adjust all window heights around the primary. */
1092 static enum tui_status
1093 tui_adjust_win_heights (struct tui_win_info *primary_win_info,
1094 int new_height)
1095 {
1096 enum tui_status status = TUI_FAILURE;
1097
1098 if (new_height_ok (primary_win_info, new_height))
1099 {
1100 status = TUI_SUCCESS;
1101 if (new_height != primary_win_info->height)
1102 {
1103 int diff;
1104 struct tui_win_info *win_info;
1105 struct tui_gen_win_info *locator = tui_locator_win_info_ptr ();
1106 enum tui_layout_type cur_layout = tui_current_layout ();
1107
1108 diff = (new_height - primary_win_info->height) * (-1);
1109 if (cur_layout == SRC_COMMAND
1110 || cur_layout == DISASSEM_COMMAND)
1111 {
1112 struct tui_win_info *src_win_info;
1113
1114 make_invisible_and_set_new_height (primary_win_info, new_height);
1115 if (primary_win_info->type == CMD_WIN)
1116 {
1117 win_info = tui_source_windows ()[0];
1118 src_win_info = win_info;
1119 }
1120 else
1121 {
1122 win_info = tui_win_list[CMD_WIN];
1123 src_win_info = primary_win_info;
1124 }
1125 make_invisible_and_set_new_height (win_info,
1126 win_info->height + diff);
1127 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
1128 win_info->make_visible_with_new_height ();
1129 primary_win_info->make_visible_with_new_height ();
1130 if (src_win_info->content_size <= 0)
1131 tui_erase_source_content (src_win_info, EMPTY_SOURCE_PROMPT);
1132 }
1133 else
1134 {
1135 struct tui_win_info *first_win;
1136 struct tui_win_info *second_win;
1137
1138 if (cur_layout == SRC_DISASSEM_COMMAND)
1139 {
1140 first_win = TUI_SRC_WIN;
1141 second_win = TUI_DISASM_WIN;
1142 }
1143 else
1144 {
1145 first_win = TUI_DATA_WIN;
1146 second_win = tui_source_windows ()[0];
1147 }
1148 if (primary_win_info == TUI_CMD_WIN)
1149 { /* Split the change in height accross the 1st & 2nd
1150 windows, adjusting them as well. */
1151 /* Subtract the locator. */
1152 int first_split_diff = diff / 2;
1153 int second_split_diff = first_split_diff;
1154
1155 if (diff % 2)
1156 {
1157 if (first_win->height >
1158 second_win->height)
1159 if (diff < 0)
1160 first_split_diff--;
1161 else
1162 first_split_diff++;
1163 else
1164 {
1165 if (diff < 0)
1166 second_split_diff--;
1167 else
1168 second_split_diff++;
1169 }
1170 }
1171 /* Make sure that the minimum hieghts are
1172 honored. */
1173 while ((first_win->height + first_split_diff) < 3)
1174 {
1175 first_split_diff++;
1176 second_split_diff--;
1177 }
1178 while ((second_win->height + second_split_diff) < 3)
1179 {
1180 second_split_diff++;
1181 first_split_diff--;
1182 }
1183 make_invisible_and_set_new_height (
1184 first_win,
1185 first_win->height + first_split_diff);
1186 second_win->origin.y = first_win->height - 1;
1187 make_invisible_and_set_new_height (second_win,
1188 second_win->height
1189 + second_split_diff);
1190 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
1191 make_invisible_and_set_new_height (TUI_CMD_WIN, new_height);
1192 }
1193 else
1194 {
1195 if ((TUI_CMD_WIN->height + diff) < 1)
1196 { /* If there is no way to increase the command
1197 window take real estate from the 1st or 2nd
1198 window. */
1199 if ((TUI_CMD_WIN->height + diff) < 1)
1200 {
1201 int i;
1202
1203 for (i = TUI_CMD_WIN->height + diff;
1204 (i < 1); i++)
1205 if (primary_win_info == first_win)
1206 second_win->height--;
1207 else
1208 first_win->height--;
1209 }
1210 }
1211 if (primary_win_info == first_win)
1212 make_invisible_and_set_new_height (first_win, new_height);
1213 else
1214 make_invisible_and_set_new_height (
1215 first_win,
1216 first_win->height);
1217 second_win->origin.y = first_win->height - 1;
1218 if (primary_win_info == second_win)
1219 make_invisible_and_set_new_height (second_win, new_height);
1220 else
1221 make_invisible_and_set_new_height (
1222 second_win, second_win->height);
1223 TUI_CMD_WIN->origin.y = locator->origin.y + 1;
1224 if ((TUI_CMD_WIN->height + diff) < 1)
1225 make_invisible_and_set_new_height (TUI_CMD_WIN, 1);
1226 else
1227 make_invisible_and_set_new_height (TUI_CMD_WIN,
1228 TUI_CMD_WIN->height + diff);
1229 }
1230 TUI_CMD_WIN->make_visible_with_new_height ();
1231 second_win->make_visible_with_new_height ();
1232 first_win->make_visible_with_new_height ();
1233 if (first_win->content_size <= 0)
1234 tui_erase_source_content (first_win, EMPTY_SOURCE_PROMPT);
1235 if (second_win->content_size <= 0)
1236 tui_erase_source_content (second_win, EMPTY_SOURCE_PROMPT);
1237 }
1238 }
1239 }
1240
1241 return status;
1242 }
1243
1244
1245 /* See tui-data.h. */
1246
1247 void
1248 tui_source_window_base::set_new_height (int height)
1249 {
1250 tui_make_invisible (execution_info);
1251 execution_info->height = height;
1252 execution_info->origin.y = origin.y;
1253 if (height > 1)
1254 execution_info->viewport_height = height - 1;
1255 else
1256 execution_info->viewport_height = height;
1257 execution_info->viewport_height--;
1258
1259 if (has_locator ())
1260 {
1261 tui_gen_win_info *gen_win_info = tui_locator_win_info_ptr ();
1262 tui_make_invisible (gen_win_info);
1263 gen_win_info->origin.y = origin.y + height;
1264 }
1265 }
1266
1267 /* See tui-data.h. */
1268
1269 void
1270 tui_data_window::set_new_height (int height)
1271 {
1272 /* Delete all data item windows. */
1273 for (int i = 0; i < content_size; i++)
1274 {
1275 struct tui_gen_win_info *gen_win_info
1276 = content[i]->which_element.data_window;
1277 tui_delete_win (gen_win_info->handle);
1278 gen_win_info->handle = NULL;
1279 }
1280 }
1281
1282 /* Function make the target window (and auxillary windows associated
1283 with the targer) invisible, and set the new height and
1284 location. */
1285 static void
1286 make_invisible_and_set_new_height (struct tui_win_info *win_info,
1287 int height)
1288 {
1289 tui_make_invisible (win_info);
1290 win_info->height = height;
1291 if (height > 1)
1292 win_info->viewport_height = height - 1;
1293 else
1294 win_info->viewport_height = height;
1295 if (win_info != TUI_CMD_WIN)
1296 win_info->viewport_height--;
1297
1298 /* Now deal with the auxillary windows associated with win_info. */
1299 win_info->set_new_height (height);
1300 }
1301
1302
1303 /* See tui-data.h. */
1304
1305 void
1306 tui_win_info::make_visible_with_new_height ()
1307 {
1308 make_visible (true);
1309 tui_check_and_display_highlight_if_needed (this);
1310 do_make_visible_with_new_height ();
1311 }
1312
1313 /* See tui-data.h. */
1314
1315 void
1316 tui_source_window_base::do_make_visible_with_new_height ()
1317 {
1318 tui_free_win_content (execution_info);
1319 tui_make_visible (execution_info);
1320 if (content != NULL)
1321 {
1322 struct tui_line_or_address line_or_addr;
1323 struct symtab_and_line cursal
1324 = get_current_source_symtab_and_line ();
1325
1326 line_or_addr = start_line_or_addr;
1327 tui_free_win_content (this);
1328 tui_update_source_window (this, gdbarch,
1329 cursal.symtab, line_or_addr, TRUE);
1330 }
1331 else if (deprecated_safe_get_selected_frame () != NULL)
1332 {
1333 struct tui_line_or_address line;
1334 struct symtab_and_line cursal
1335 = get_current_source_symtab_and_line ();
1336 struct frame_info *frame = deprecated_safe_get_selected_frame ();
1337 struct gdbarch *gdbarch = get_frame_arch (frame);
1338
1339 struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
1340 if (type == SRC_WIN)
1341 {
1342 line.loa = LOA_LINE;
1343 line.u.line_no = cursal.line;
1344 }
1345 else
1346 {
1347 line.loa = LOA_ADDRESS;
1348 find_line_pc (s, cursal.line, &line.u.addr);
1349 }
1350 tui_update_source_window (this, gdbarch, s, line, TRUE);
1351 }
1352 if (has_locator ())
1353 {
1354 tui_make_visible (tui_locator_win_info_ptr ());
1355 tui_show_locator_content ();
1356 }
1357 }
1358
1359 /* See tui-data.h. */
1360
1361 void
1362 tui_data_window::do_make_visible_with_new_height ()
1363 {
1364 tui_display_all_data ();
1365 }
1366
1367 /* See tui-data.h. */
1368
1369 void
1370 tui_cmd_window::do_make_visible_with_new_height ()
1371 {
1372 #ifdef HAVE_WRESIZE
1373 wresize (handle, height, width);
1374 #endif
1375 mvwin (handle, origin.y, origin.x);
1376 wmove (handle, 0, 0);
1377 }
1378
1379 /* See tui-data.h. */
1380
1381 int
1382 tui_win_info::max_height () const
1383 {
1384 return tui_term_height () - 2;
1385 }
1386
1387 /* See tui-data.h. */
1388
1389 int
1390 tui_cmd_window::max_height () const
1391 {
1392 return tui_term_height () - 4;
1393 }
1394
1395 static int
1396 new_height_ok (struct tui_win_info *primary_win_info,
1397 int new_height)
1398 {
1399 int ok = (new_height < tui_term_height ());
1400
1401 if (ok)
1402 {
1403 int diff;
1404 enum tui_layout_type cur_layout = tui_current_layout ();
1405
1406 diff = (new_height - primary_win_info->height) * (-1);
1407 if (cur_layout == SRC_COMMAND || cur_layout == DISASSEM_COMMAND)
1408 {
1409 ok = (new_height <= primary_win_info->max_height ()
1410 && new_height >= MIN_CMD_WIN_HEIGHT);
1411 if (ok)
1412 { /* Check the total height. */
1413 struct tui_win_info *win_info;
1414
1415 if (primary_win_info == TUI_CMD_WIN)
1416 win_info = tui_source_windows ()[0];
1417 else
1418 win_info = TUI_CMD_WIN;
1419 ok = ((new_height +
1420 (win_info->height + diff)) <= tui_term_height ());
1421 }
1422 }
1423 else
1424 {
1425 int cur_total_height, total_height, min_height = 0;
1426 struct tui_win_info *first_win;
1427 struct tui_win_info *second_win;
1428
1429 if (cur_layout == SRC_DISASSEM_COMMAND)
1430 {
1431 first_win = TUI_SRC_WIN;
1432 second_win = TUI_DISASM_WIN;
1433 }
1434 else
1435 {
1436 first_win = TUI_DATA_WIN;
1437 second_win = tui_source_windows ()[0];
1438 }
1439 /* We could simply add all the heights to obtain the same
1440 result but below is more explicit since we subtract 1 for
1441 the line that the first and second windows share, and add
1442 one for the locator. */
1443 total_height = cur_total_height =
1444 (first_win->height + second_win->height - 1)
1445 + TUI_CMD_WIN->height + 1; /* Locator. */
1446 if (primary_win_info == TUI_CMD_WIN)
1447 {
1448 /* Locator included since first & second win share a line. */
1449 ok = ((first_win->height +
1450 second_win->height + diff) >=
1451 (MIN_WIN_HEIGHT * 2)
1452 && new_height >= MIN_CMD_WIN_HEIGHT);
1453 if (ok)
1454 {
1455 total_height = new_height +
1456 (first_win->height +
1457 second_win->height + diff);
1458 min_height = MIN_CMD_WIN_HEIGHT;
1459 }
1460 }
1461 else
1462 {
1463 min_height = MIN_WIN_HEIGHT;
1464
1465 /* First see if we can increase/decrease the command
1466 window. And make sure that the command window is at
1467 least 1 line. */
1468 ok = ((TUI_CMD_WIN->height + diff) > 0);
1469 if (!ok)
1470 { /* Looks like we have to increase/decrease one of
1471 the other windows. */
1472 if (primary_win_info == first_win)
1473 ok = (second_win->height + diff) >= min_height;
1474 else
1475 ok = (first_win->height + diff) >= min_height;
1476 }
1477 if (ok)
1478 {
1479 if (primary_win_info == first_win)
1480 total_height = new_height +
1481 second_win->height +
1482 TUI_CMD_WIN->height + diff;
1483 else
1484 total_height = new_height +
1485 first_win->height +
1486 TUI_CMD_WIN->height + diff;
1487 }
1488 }
1489 /* Now make sure that the proposed total height doesn't
1490 exceed the old total height. */
1491 if (ok)
1492 ok = (new_height >= min_height
1493 && total_height <= cur_total_height);
1494 }
1495 }
1496
1497 return ok;
1498 }
1499
1500
1501 static void
1502 parse_scrolling_args (const char *arg,
1503 struct tui_win_info **win_to_scroll,
1504 int *num_to_scroll)
1505 {
1506 if (num_to_scroll)
1507 *num_to_scroll = 0;
1508 *win_to_scroll = tui_win_with_focus ();
1509
1510 /* First set up the default window to scroll, in case there is no
1511 window name arg. */
1512 if (arg != NULL)
1513 {
1514 char *buf_ptr;
1515
1516 /* Process the number of lines to scroll. */
1517 std::string copy = arg;
1518 buf_ptr = &copy[0];
1519 if (isdigit (*buf_ptr))
1520 {
1521 char *num_str;
1522
1523 num_str = buf_ptr;
1524 buf_ptr = strchr (buf_ptr, ' ');
1525 if (buf_ptr != NULL)
1526 {
1527 *buf_ptr = (char) 0;
1528 if (num_to_scroll)
1529 *num_to_scroll = atoi (num_str);
1530 buf_ptr++;
1531 }
1532 else if (num_to_scroll)
1533 *num_to_scroll = atoi (num_str);
1534 }
1535
1536 /* Process the window name if one is specified. */
1537 if (buf_ptr != NULL)
1538 {
1539 const char *wname;
1540
1541 if (*buf_ptr == ' ')
1542 while (*(++buf_ptr) == ' ')
1543 ;
1544
1545 if (*buf_ptr != (char) 0)
1546 {
1547 /* Validate the window name. */
1548 for (char *p = buf_ptr; *p != '\0'; p++)
1549 *p = tolower (*p);
1550
1551 wname = buf_ptr;
1552 }
1553 else
1554 wname = "?";
1555
1556 *win_to_scroll = tui_partial_win_by_name (wname);
1557
1558 if (*win_to_scroll == NULL
1559 || !(*win_to_scroll)->is_visible)
1560 error (_("Invalid window specified. \n\
1561 The window name specified must be valid and visible.\n"));
1562 else if (*win_to_scroll == TUI_CMD_WIN)
1563 *win_to_scroll = tui_source_windows ()[0];
1564 }
1565 }
1566 }
1567
1568 /* Function to initialize gdb commands, for tui window
1569 manipulation. */
1570
1571 void
1572 _initialize_tui_win (void)
1573 {
1574 static struct cmd_list_element *tui_setlist;
1575 static struct cmd_list_element *tui_showlist;
1576 struct cmd_list_element *cmd;
1577
1578 /* Define the classes of commands.
1579 They will appear in the help list in the reverse of this order. */
1580 add_prefix_cmd ("tui", class_tui, set_tui_cmd,
1581 _("TUI configuration variables"),
1582 &tui_setlist, "set tui ",
1583 0 /* allow-unknown */, &setlist);
1584 add_prefix_cmd ("tui", class_tui, show_tui_cmd,
1585 _("TUI configuration variables"),
1586 &tui_showlist, "show tui ",
1587 0 /* allow-unknown */, &showlist);
1588
1589 add_com ("refresh", class_tui, tui_refresh_all_command,
1590 _("Refresh the terminal display."));
1591
1592 cmd = add_com ("tabset", class_tui, tui_set_tab_width_command, _("\
1593 Set the width (in characters) of tab stops.\n\
1594 Usage: tabset N"));
1595 deprecate_cmd (cmd, "set tui tab-width");
1596
1597 cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
1598 Set or modify the height of a specified window.\n"
1599 WIN_HEIGHT_USAGE
1600 "Window names are:\n\
1601 src : the source window\n\
1602 cmd : the command window\n\
1603 asm : the disassembly window\n\
1604 regs : the register display"));
1605 add_com_alias ("wh", "winheight", class_tui, 0);
1606 set_cmd_completer (cmd, winheight_completer);
1607 add_info ("win", tui_all_windows_info,
1608 _("List of all displayed windows."));
1609 cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
1610 Set focus to named window or next/prev window.\n"
1611 FOCUS_USAGE
1612 "Valid Window names are:\n\
1613 src : the source window\n\
1614 asm : the disassembly window\n\
1615 regs : the register display\n\
1616 cmd : the command window"));
1617 add_com_alias ("fs", "focus", class_tui, 0);
1618 set_cmd_completer (cmd, focus_completer);
1619 add_com ("+", class_tui, tui_scroll_forward_command, _("\
1620 Scroll window forward.\n\
1621 Usage: + [WIN] [N]"));
1622 add_com ("-", class_tui, tui_scroll_backward_command, _("\
1623 Scroll window backward.\n\
1624 Usage: - [WIN] [N]"));
1625 add_com ("<", class_tui, tui_scroll_left_command, _("\
1626 Scroll window text to the left.\n\
1627 Usage: < [WIN] [N]"));
1628 add_com (">", class_tui, tui_scroll_right_command, _("\
1629 Scroll window text to the right.\n\
1630 Usage: > [WIN] [N]"));
1631
1632 /* Define the tui control variables. */
1633 add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,
1634 &tui_border_kind, _("\
1635 Set the kind of border for TUI windows."), _("\
1636 Show the kind of border for TUI windows."), _("\
1637 This variable controls the border of TUI windows:\n\
1638 space use a white space\n\
1639 ascii use ascii characters + - | for the border\n\
1640 acs use the Alternate Character Set"),
1641 tui_set_var_cmd,
1642 show_tui_border_kind,
1643 &tui_setlist, &tui_showlist);
1644
1645 add_setshow_enum_cmd ("border-mode", no_class, tui_border_mode_enums,
1646 &tui_border_mode, _("\
1647 Set the attribute mode to use for the TUI window borders."), _("\
1648 Show the attribute mode to use for the TUI window borders."), _("\
1649 This variable controls the attributes to use for the window borders:\n\
1650 normal normal display\n\
1651 standout use highlight mode of terminal\n\
1652 reverse use reverse video mode\n\
1653 half use half bright\n\
1654 half-standout use half bright and standout mode\n\
1655 bold use extra bright or bold\n\
1656 bold-standout use extra bright or bold with standout mode"),
1657 tui_set_var_cmd,
1658 show_tui_border_mode,
1659 &tui_setlist, &tui_showlist);
1660
1661 add_setshow_enum_cmd ("active-border-mode", no_class, tui_border_mode_enums,
1662 &tui_active_border_mode, _("\
1663 Set the attribute mode to use for the active TUI window border."), _("\
1664 Show the attribute mode to use for the active TUI window border."), _("\
1665 This variable controls the attributes to use for the active window border:\n\
1666 normal normal display\n\
1667 standout use highlight mode of terminal\n\
1668 reverse use reverse video mode\n\
1669 half use half bright\n\
1670 half-standout use half bright and standout mode\n\
1671 bold use extra bright or bold\n\
1672 bold-standout use extra bright or bold with standout mode"),
1673 tui_set_var_cmd,
1674 show_tui_active_border_mode,
1675 &tui_setlist, &tui_showlist);
1676
1677 add_setshow_zuinteger_cmd ("tab-width", no_class,
1678 &internal_tab_width, _("\
1679 Set the tab width, in characters, for the TUI."), _("\
1680 Show the tab witdh, in characters, for the TUI"), _("\
1681 This variable controls how many spaces are used to display a tab character."),
1682 tui_set_tab_width, tui_show_tab_width,
1683 &tui_setlist, &tui_showlist);
1684 }
This page took 0.065808 seconds and 4 git commands to generate.