diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-01-24 22:02:59 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-04-03 15:15:09 +0100 |
commit | 160444ec7fd7c6df81826b8e06aa32a2ac1df856 (patch) | |
tree | 203f32b2a5e84359ef9756ce50e1b5f64553eb6d /gdb/tui/tui-win.c | |
parent | ef466e0f0827555fcae21a905b3a2b9a6c0a5712 (diff) | |
download | fsf-binutils-gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.zip fsf-binutils-gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.tar.gz fsf-binutils-gdb-160444ec7fd7c6df81826b8e06aa32a2ac1df856.tar.bz2 |
gdb/tui: add new 'tui window width' command and 'winwidth' alias
This commit adds a new command 'tui window width', and an alias
'winwidth'. This command is equivalent to the old 'winheight'
command (which was recently renamed 'tui window height').
Even though I recently moved the old tui commands under the tui
namespace, and I would strongly encourage all new tui commands to be
added as 'tui ....' only (users can create their own top-level aliases
if they want), I'm breaking that suggestion here, and adding a
'winwidth' alias.
Given that we already have 'winheight' and have done for years, it
just didn't seem right to no have the matching 'winwidth'.
You might notice in the test that the window resizing doesn't quite
work right. I setup a horizontal layout, then grow and shrink the
windows. At the end of the test the windows should be back to their
original size...
... they are not. This isn't my fault, honest! GDB's window resizing
is a little ... temperamental, and is prone to getting things slightly
wrong during resizes, off by 1 type things. This is true for height
resizing, as well as the new width resizing.
Later patches in this series will rework the resizing algorithm, which
should improve things in this area. For now, I'm happy that the width
resizing is as good as the height resizing, given the existing quirks.
For the docs side I include a paragraph that explains how multiple
windows are required before the width can be adjusted. For
completeness, I've added the same paragraph to the winheight
description. With the predefined layouts this extra paragraph is not
really needed for winheight, as there are always multiple windows on
the screen. However, with custom layouts, this might not be true, so
adding the paragraph seems like a good idea.
As for the changes in gdb itself, I've mostly just taken the existing
height adjustment code, changed the name to make it generic 'size'
adjustment, and added a boolean flag to indicate if we are adjusting
the width or the height.
Diffstat (limited to 'gdb/tui/tui-win.c')
-rw-r--r-- | gdb/tui/tui-win.c | 68 |
1 files changed, 61 insertions, 7 deletions
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 1371861..8564f9e 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -842,10 +842,21 @@ tui_set_tab_width_command (const char *arg, int from_tty) } } +/* Helper function for the user commands to adjust a window's width or + height. The ARG string contains the command line arguments from the + user, which should give the name of a window, and how to adjust the + size. + + When SET_WIDTH_P is true the width of the window is adjusted based on + ARG, and when SET_WIDTH_P is false, the height of the window is adjusted + based on ARG. + + On invalid input, or if the size can't be adjusted as requested, then an + error is thrown, otherwise, the window sizes are adjusted, and the + windows redrawn. */ -/* Set the height of the specified window. */ static void -tui_set_win_height_command (const char *arg, int from_tty) +tui_set_win_size (const char *arg, bool set_width_p) { /* Make sure the curses mode is enabled. */ tui_enable (); @@ -854,7 +865,7 @@ tui_set_win_height_command (const char *arg, int from_tty) const char *buf = arg; const char *buf_ptr = buf; - int new_height; + int new_size; struct tui_win_info *win_info; buf_ptr = skip_to_space (buf_ptr); @@ -890,20 +901,53 @@ tui_set_win_height_command (const char *arg, int from_tty) if (negate) input_no *= (-1); if (fixed_size) - new_height = input_no; + new_size = input_no; else - new_height = win_info->height + input_no; + { + int curr_size; + if (set_width_p) + curr_size = win_info->width; + else + curr_size = win_info->height; + new_size = curr_size + input_no; + } /* Now change the window's height, and adjust all other windows around it. */ - tui_adjust_window_height (win_info, new_height); + if (set_width_p) + tui_adjust_window_width (win_info, new_size); + else + tui_adjust_window_height (win_info, new_size); tui_update_gdb_sizes (); } else - error (_("Invalid window height specified")); + { + if (set_width_p) + error (_("Invalid window width specified")); + else + error (_("Invalid window height specified")); + } } } +/* Implement the 'tui window height' command (alias 'winheight'). */ + +static void +tui_set_win_height_command (const char *arg, int from_tty) +{ + /* Pass false as the final argument to set the height. */ + tui_set_win_size (arg, false); +} + +/* Implement the 'tui window width' command (alias 'winwidth'). */ + +static void +tui_set_win_width_command (const char *arg, int from_tty) +{ + /* Pass true as the final argument to set the width. */ + tui_set_win_size (arg, true); +} + /* See tui-data.h. */ int @@ -1033,6 +1077,16 @@ Use \"info win\" to see the names of the windows currently being displayed."), add_com_alias ("winheight", winheight_cmd, class_tui, 0); add_com_alias ("wh", winheight_cmd, class_tui, 0); set_cmd_completer (winheight_cmd, winheight_completer); + + cmd_list_element *winwidth_cmd + = add_cmd ("width", class_tui, tui_set_win_width_command, _("\ +Set or modify the width of a specified window.\n\ +Usage: tui window width WINDOW-NAME [+ | -] NUM-LINES\n\ +Use \"info win\" to see the names of the windows currently being displayed."), + &tui_window_cmds); + add_com_alias ("winwidth", winwidth_cmd, class_tui, 0); + set_cmd_completer (winwidth_cmd, winheight_completer); + add_info ("win", tui_all_windows_info, _("List of all displayed windows.\n\ Usage: info win")); |