/* TUI window generic functions.
- Copyright (C) 1998-2019 Free Software Foundation, Inc.
+ Copyright (C) 1998-2020 Free Software Foundation, Inc.
Contributed by Hewlett-Packard Company.
#include "cli/cli-style.h"
#include "top.h"
#include "source.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
#include "gdbcmd.h"
+#include "async-event.h"
#include "tui/tui.h"
#include "tui/tui-io.h"
int *);
-#define WIN_HEIGHT_USAGE "Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n"
-#define FOCUS_USAGE "Usage: focus [WINDOW-NAME | next | prev]\n"
-
#ifndef ACS_LRCORNER
# define ACS_LRCORNER '+'
#endif
static struct cmd_list_element *tuilist;
-static void
-tui_command (const char *args, int from_tty)
-{
- printf_unfiltered (_("\"tui\" must be followed by the name of a "
- "tui command.\n"));
- help_list (tuilist, "tui ", all_commands, gdb_stdout);
-}
-
struct cmd_list_element **
tui_get_cmd_list (void)
{
if (tuilist == 0)
- add_prefix_cmd ("tui", class_tui, tui_command,
- _("Text User Interface commands."),
- &tuilist, "tui ", 0, &cmdlist);
+ add_basic_prefix_cmd ("tui", class_tui,
+ _("Text User Interface commands."),
+ &tuilist, "tui ", 0, &cmdlist);
return &tuilist;
}
/* If no windows are considered visible then the TUI has not yet been
initialized. But still "focus src" and "focus cmd" will work because
invoking the focus command will entail initializing the TUI which sets the
- default layout to SRC_COMMAND. */
+ default layout to "src". */
if (completion_name_vec.empty ())
{
completion_name_vec.push_back (SRC_NAME);
}
-/* Set the logical focus to win_info. */
-void
-tui_set_win_focus_to (struct tui_win_info *win_info)
-{
- if (win_info != NULL)
- {
- struct tui_win_info *win_with_focus = tui_win_with_focus ();
-
- tui_unhighlight_win (win_with_focus);
- tui_set_win_with_focus (win_info);
- tui_highlight_win (win_info);
- }
-}
-
-
void
tui_win_info::forward_scroll (int num_to_scroll)
{
erase ();
clearok (curscr, TRUE);
tui_apply_current_layout ();
- tui_delete_invisible_windows ();
/* Turn keypad back on, unless focus is in the command
window. */
if (win_with_focus != TUI_CMD_WIN)
static struct tui_win_info *
tui_partial_win_by_name (gdb::string_view name)
{
+ struct tui_win_info *best = nullptr;
+
if (name != NULL)
{
for (tui_win_info *item : all_tui_windows ())
{
const char *cur_name = item->name ();
- if (startswith (cur_name, name))
+ if (name == cur_name)
return item;
+ if (startswith (cur_name, name))
+ {
+ if (best != nullptr)
+ error (_("Window name \"%*s\" is ambiguous"),
+ (int) name.size (), name.data ());
+ best = item;
+ }
}
}
- return NULL;
+ return best;
}
/* Set focus to the window named by 'arg'. */
{
tui_enable ();
- if (arg != NULL)
- {
- struct tui_win_info *win_info = NULL;
-
- if (subset_compare (arg, "next"))
- win_info = tui_next_win (tui_win_with_focus ());
- else if (subset_compare (arg, "prev"))
- win_info = tui_prev_win (tui_win_with_focus ());
- else
- win_info = tui_partial_win_by_name (arg);
+ if (arg == NULL)
+ error_no_arg (_("name of window to focus"));
- if (win_info == NULL)
- error (_("Unrecognized window name \"%s\""), arg);
- if (!win_info->is_visible ())
- error (_("Window \"%s\" is not visible"), arg);
+ struct tui_win_info *win_info = NULL;
- tui_set_win_focus_to (win_info);
- keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
- printf_filtered (_("Focus set to %s window.\n"),
- tui_win_with_focus ()->name ());
- }
+ if (subset_compare (arg, "next"))
+ win_info = tui_next_win (tui_win_with_focus ());
+ else if (subset_compare (arg, "prev"))
+ win_info = tui_prev_win (tui_win_with_focus ());
else
- error (_("Incorrect Number of Arguments.\n%s"), FOCUS_USAGE);
+ win_info = tui_partial_win_by_name (arg);
+
+ if (win_info == NULL)
+ error (_("Unrecognized window name \"%s\""), arg);
+ if (!win_info->is_visible ())
+ error (_("Window \"%s\" is not visible"), arg);
+
+ tui_set_win_focus_to (win_info);
+ keypad (TUI_CMD_WIN->handle.get (), win_info != TUI_CMD_WIN);
+ printf_filtered (_("Focus set to %s window.\n"),
+ tui_win_with_focus ()->name ());
}
static void
{
/* Make sure the curses mode is enabled. */
tui_enable ();
- if (arg != NULL)
- {
- const char *buf = arg;
- const char *buf_ptr = buf;
- int new_height;
- struct tui_win_info *win_info;
+ if (arg == NULL)
+ error_no_arg (_("name of window"));
- buf_ptr = strchr (buf_ptr, ' ');
- if (buf_ptr != NULL)
- {
- /* Validate the window name. */
- gdb::string_view wname (buf, buf_ptr - buf);
- win_info = tui_partial_win_by_name (wname);
+ const char *buf = arg;
+ const char *buf_ptr = buf;
+ int new_height;
+ struct tui_win_info *win_info;
- if (win_info == NULL)
- error (_("Unrecognized window name \"%s\""), arg);
- if (!win_info->is_visible ())
- error (_("Window \"%s\" is not visible"), arg);
+ buf_ptr = skip_to_space (buf_ptr);
- /* Process the size. */
- buf_ptr = skip_spaces (buf_ptr);
+ /* Validate the window name. */
+ gdb::string_view wname (buf, buf_ptr - buf);
+ win_info = tui_partial_win_by_name (wname);
- if (*buf_ptr != '\0')
- {
- bool negate = false;
- bool fixed_size = true;
- int input_no;;
-
- if (*buf_ptr == '+' || *buf_ptr == '-')
- {
- if (*buf_ptr == '-')
- negate = true;
- fixed_size = false;
- buf_ptr++;
- }
- input_no = atoi (buf_ptr);
- if (input_no > 0)
- {
- if (negate)
- input_no *= (-1);
- if (fixed_size)
- new_height = input_no;
- else
- new_height = win_info->height + input_no;
-
- /* Now change the window's height, and adjust
- all other windows around it. */
- tui_adjust_window_height (win_info, new_height);
- tui_update_gdb_sizes ();
- }
- else
- warning (_("Invalid window height specified.\n%s"),
- WIN_HEIGHT_USAGE);
- }
+ if (win_info == NULL)
+ error (_("Unrecognized window name \"%s\""), arg);
+ if (!win_info->is_visible ())
+ error (_("Window \"%s\" is not visible"), arg);
+
+ /* Process the size. */
+ buf_ptr = skip_spaces (buf_ptr);
+
+ if (*buf_ptr != '\0')
+ {
+ bool negate = false;
+ bool fixed_size = true;
+ int input_no;;
+
+ if (*buf_ptr == '+' || *buf_ptr == '-')
+ {
+ if (*buf_ptr == '-')
+ negate = true;
+ fixed_size = false;
+ buf_ptr++;
+ }
+ input_no = atoi (buf_ptr);
+ if (input_no > 0)
+ {
+ if (negate)
+ input_no *= (-1);
+ if (fixed_size)
+ new_height = input_no;
+ else
+ new_height = win_info->height + input_no;
+
+ /* Now change the window's height, and adjust
+ all other windows around it. */
+ tui_adjust_window_height (win_info, new_height);
+ tui_update_gdb_sizes ();
}
else
- printf_filtered (WIN_HEIGHT_USAGE);
+ error (_("Invalid window height specified"));
}
- else
- printf_filtered (WIN_HEIGHT_USAGE);
}
/* See tui-data.h. */
return tui_term_height () - 2;
}
+/* See tui-data.h. */
+
+int
+tui_gen_win_info::max_width () const
+{
+ return tui_term_width () - 2;
+}
+
static void
parse_scrolling_args (const char *arg,
struct tui_win_info **win_to_scroll,
/* Function to initialize gdb commands, for tui window
manipulation. */
+void _initialize_tui_win ();
void
-_initialize_tui_win (void)
+_initialize_tui_win ()
{
static struct cmd_list_element *tui_setlist;
static struct cmd_list_element *tui_showlist;
deprecate_cmd (cmd, "set tui tab-width");
cmd = add_com ("winheight", class_tui, tui_set_win_height_command, _("\
-Set or modify the height of a specified window.\n"
-WIN_HEIGHT_USAGE
-"Window names are:\n\
- src : the source window\n\
- cmd : the command window\n\
- asm : the disassembly window\n\
- regs : the register display"));
+Set or modify the height of a specified window.\n\
+Usage: winheight WINDOW-NAME [+ | -] NUM-LINES\n\
+Use \"info win\" to see the names of the windows currently being displayed."));
add_com_alias ("wh", "winheight", class_tui, 0);
set_cmd_completer (cmd, winheight_completer);
add_info ("win", tui_all_windows_info,
- _("List of all displayed windows."));
+ _("List of all displayed windows.\n\
+Usage: info win"));
cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\
-Set focus to named window or next/prev window.\n"
-FOCUS_USAGE
-"Valid Window names are:\n\
- src : the source window\n\
- asm : the disassembly window\n\
- regs : the register display\n\
- cmd : the command window"));
+Set focus to named window or next/prev window.\n\
+Usage: focus [WINDOW-NAME | next | prev]\n\
+Use \"info win\" to see the names of the windows currently being displayed."));
add_com_alias ("fs", "focus", class_tui, 0);
set_cmd_completer (cmd, focus_completer);
add_com ("+", class_tui, tui_scroll_forward_command, _("\
Scroll window forward.\n\
-Usage: + [WIN] [N]"));
+Usage: + [N] [WIN]\n\
+Scroll window WIN N lines forwards. Both WIN and N are optional, N\n\
+defaults to 1, and WIN defaults to the currently focused window."));
add_com ("-", class_tui, tui_scroll_backward_command, _("\
Scroll window backward.\n\
-Usage: - [WIN] [N]"));
+Usage: - [N] [WIN]\n\
+Scroll window WIN N lines backwards. Both WIN and N are optional, N\n\
+defaults to 1, and WIN defaults to the currently focused window."));
add_com ("<", class_tui, tui_scroll_left_command, _("\
Scroll window text to the left.\n\
-Usage: < [WIN] [N]"));
+Usage: < [N] [WIN]\n\
+Scroll window WIN N characters left. Both WIN and N are optional, N\n\
+defaults to 1, and WIN defaults to the currently focused window."));
add_com (">", class_tui, tui_scroll_right_command, _("\
Scroll window text to the right.\n\
-Usage: > [WIN] [N]"));
+Usage: > [N] [WIN]\n\
+Scroll window WIN N characters right. Both WIN and N are optional, N\n\
+defaults to 1, and WIN defaults to the currently focused window."));
/* Define the tui control variables. */
add_setshow_enum_cmd ("border-kind", no_class, tui_border_kind_enums,