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