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