From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 237F3385781E for ; Mon, 7 Mar 2022 22:14:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 237F3385781E Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-gsy1EbiUN6euqCulfVS6Gw-1; Mon, 07 Mar 2022 17:13:58 -0500 X-MC-Unique: gsy1EbiUN6euqCulfVS6Gw-1 Received: by mail-wm1-f70.google.com with SMTP id l2-20020a1ced02000000b0038482a47e7eso220591wmh.5 for ; Mon, 07 Mar 2022 14:13:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kH3FJODFm0Lz+g44Z7y4SfMkiiVDJnn12VtIF3GJArc=; b=nGqinkLliPa248lFM0bnsRmx3u5zwHepYwoPrEoWHbacWwCtWpVDUHxzeFQpAuxsow WgpoC2H4uBox4pQR/JIgShMbPKtbfC89epxiwSnwdiCRo5P+cH2RQ4S1PbdcZ1AJkrkt xt4k/XqQIp1VKktNzCmv8eQfAdPJbNmOoxQTbhIl+zyoMxyZ+oKl2ol6TlFlwRipAy4y ESWxAaosbFOgCXVH4imTpVHHXsFNAXU7E1J0Sa0RlnuPdkAgz3a4rijEY/u601vnTzqO T7N3JYsSHH80iqgUOFxhuhcQJWwLrjoveNBN1b2G392vB0uuViDxJPAXybv9xTj3PhO7 q5XA== X-Gm-Message-State: AOAM531nBWkyPN28WhFcuKuzSvCVO25+XQEs1noxs4OQoLYQt42RHvaO /udIXSKvQ+ljINfDQyKGECDkSSmJI1O8VL5WCLIf+d3bWprrOUm9S79/3P7egPGlNBzVJ5mg1LD M5kNU/8LsoviJ2FemPoD4b4t9/eu9VjgjUpd8YORUTNjMr4azAyLXr05S5p8rssnUwNc/5BKjqg == X-Received: by 2002:a05:6000:154b:b0:1f0:6019:ea3a with SMTP id 11-20020a056000154b00b001f06019ea3amr9730822wry.395.1646691237138; Mon, 07 Mar 2022 14:13:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwv8H7YgmZx0XV1uxAXrte1lAXgb0ycI20c3mqfp3LxKaWFcPmL22KROIspDe6eGQwYdLwONQ== X-Received: by 2002:a05:6000:154b:b0:1f0:6019:ea3a with SMTP id 11-20020a056000154b00b001f06019ea3amr9730798wry.395.1646691236611; Mon, 07 Mar 2022 14:13:56 -0800 (PST) Received: from localhost (host86-134-151-205.range86-134.btcentralplus.com. [86.134.151.205]) by smtp.gmail.com with ESMTPSA id k10-20020adfe3ca000000b001f0329ba94csm20388718wrm.18.2022.03.07.14.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 14:13:56 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 05/15] gdb/tui: add new 'tui window width' command and 'winwidth' alias Date: Mon, 7 Mar 2022 22:13:37 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Mar 2022 22:14:03 -0000 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. --- gdb/NEWS | 6 +++ gdb/doc/gdb.texinfo | 22 ++++++++++ gdb/testsuite/gdb.tui/winwidth.exp | 62 +++++++++++++++++++++++++++ gdb/tui/tui-layout.c | 33 +++++++++++---- gdb/tui/tui-layout.h | 34 ++++++++++++++- gdb/tui/tui-win.c | 68 +++++++++++++++++++++++++++--- 6 files changed, 209 insertions(+), 16 deletions(-) create mode 100644 gdb/testsuite/gdb.tui/winwidth.exp diff --git a/gdb/NEWS b/gdb/NEWS index 3c3e0bbb2fb..1275d967a2d 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -127,6 +127,12 @@ tui window height and 'winheight' tui commands respectively. The old names still exist as aliases to these new commands. +tui window width +winwidth + The new command 'tui window width', and the alias 'winwidth' allow + the width of a tui window to be adjusted when windows are laid out + in horizontal mode. + * Changed commands maint packet diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index fd4c110569e..6081aa85af4 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -29115,6 +29115,28 @@ it. The @var{name} parameter can be the name of any currently visible window. The names of the currently visible windows can be discovered using @kbd{info win} (@pxref{info_win_command,,info win}). + +The set of currently visible windows must always fill the terminal, +and so, it is only possible to resize on window if there are other +visible windows that can either give or receive the extra terminal +space. + +@kindex tui window width +@kindex winwidth +@item tui window width @var{name} +@var{count} +@itemx tui window width @var{name} -@var{count} +@itemx winwidth @var{name} +@var{count} +@itemx winwidth @var{name} -@var{count} +Change the width of the window @var{name} by @var{count} columns. +Positive counts increase the width, while negative counts decrease it. +The @var{name} parameter can be the name of any currently visible +window. The names of the currently visible windows can be discovered +using @code{info win} (@pxref{info_win_command,,info win}). + +The set of currently visible windows must always fill the terminal, +and so, it is only possible to resize on window if there are other +visible windows that can either give or receive the extra terminal +space. @end table @node TUI Configuration diff --git a/gdb/testsuite/gdb.tui/winwidth.exp b/gdb/testsuite/gdb.tui/winwidth.exp new file mode 100644 index 00000000000..b0a838b578f --- /dev/null +++ b/gdb/testsuite/gdb.tui/winwidth.exp @@ -0,0 +1,62 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test the "winwidth" command. + +tuiterm_env + +standard_testfile tui-layout.c + +if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { + return -1 +} + +Term::clean_restart 24 80 $testfile +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + +Term::command "tui new-layout h { -horizontal src 1 asm 1 } 1 status 0 cmd 1" +Term::command "layout h" + +with_test_prefix "original window sizes" { + Term::check_box "source box" 0 0 40 15 + Term::check_box "asm box" 39 0 41 15 + Term::command "winwidth src +5" +} + +with_test_prefix "after src +5" { + Term::check_box "source box" 0 0 44 15 + Term::check_box "asm box" 43 0 37 15 + Term::command "winwidth asm -5" +} + +with_test_prefix "after asm -5" { + Term::check_box "source box" 0 0 48 15 + Term::check_box "asm box" 47 0 33 15 + Term::command "winwidth asm +8" +} + +with_test_prefix "after asm +8" { + Term::check_box "source box" 0 0 39 15 + Term::check_box "asm box" 38 0 42 15 + Term::command "winwidth src -2" +} + +with_test_prefix "after src -2" { + Term::check_box "source box" 0 0 36 15 + Term::check_box "asm box" 35 0 45 15 +} diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 9e856ccf3fa..4e5740fd6d3 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -121,6 +121,14 @@ tui_adjust_window_height (struct tui_win_info *win, int new_height) applied_layout->set_height (win->name (), new_height); } +/* See tui-layout. */ + +void +tui_adjust_window_width (struct tui_win_info *win, int new_width) +{ + applied_layout->set_width (win->name (), new_width); +} + /* Set the current layout to LAYOUT. */ static void @@ -571,7 +579,7 @@ tui_layout_split::set_weights_from_sizes () /* See tui-layout.h. */ tui_adjust_result -tui_layout_split::set_height (const char *name, int new_height) +tui_layout_split::set_size (const char *name, int new_size, bool set_width_p) { /* Look through the children. If one is a layout holding the named window, we're done; or if one actually is the named window, @@ -579,13 +587,16 @@ tui_layout_split::set_height (const char *name, int new_height) int found_index = -1; for (int i = 0; i < m_splits.size (); ++i) { - tui_adjust_result adjusted - = m_splits[i].layout->set_height (name, new_height); + tui_adjust_result adjusted; + if (set_width_p) + adjusted = m_splits[i].layout->set_width (name, new_size); + else + adjusted = m_splits[i].layout->set_height (name, new_size); if (adjusted == HANDLED) return HANDLED; if (adjusted == FOUND) { - if (!m_vertical) + if (set_width_p ? m_vertical : !m_vertical) return FOUND; found_index = i; break; @@ -594,12 +605,15 @@ tui_layout_split::set_height (const char *name, int new_height) if (found_index == -1) return NOT_FOUND; - if (m_splits[found_index].layout->height == new_height) + int curr_size = (set_width_p + ? m_splits[found_index].layout->width + : m_splits[found_index].layout->height); + if (curr_size == new_size) return HANDLED; set_weights_from_sizes (); - int delta = m_splits[found_index].weight - new_height; - m_splits[found_index].weight = new_height; + int delta = m_splits[found_index].weight - new_size; + m_splits[found_index].weight = new_size; /* Distribute the "delta" over the next window; but if the next window cannot hold it all, keep going until we either find a @@ -633,7 +647,10 @@ tui_layout_split::set_height (const char *name, int new_height) if (delta != 0) { - warning (_("Invalid window height specified")); + if (set_width_p) + warning (_("Invalid window width specified")); + else + warning (_("Invalid window height specified")); /* Effectively undo any modifications made here. */ set_weights_from_sizes (); } diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h index 8f41835b94c..79ad0b8dafc 100644 --- a/gdb/tui/tui-layout.h +++ b/gdb/tui/tui-layout.h @@ -79,6 +79,10 @@ class tui_layout_base the sizes of the other windows around it. */ virtual tui_adjust_result set_height (const char *name, int new_height) = 0; + /* Set the width of the window named NAME to NEW_WIDTH, updating + the sizes of the other windows around it. */ + virtual tui_adjust_result set_width (const char *name, int new_width) = 0; + /* Remove some windows from the layout, leaving the command window and the window being passed in here. */ virtual void remove_windows (const char *name) = 0; @@ -132,6 +136,11 @@ class tui_layout_window : public tui_layout_base return m_contents == name ? FOUND : NOT_FOUND; } + tui_adjust_result set_width (const char *name, int new_width) override + { + return m_contents == name ? FOUND : NOT_FOUND; + } + bool top_boxed_p () const override; bool bottom_boxed_p () const override; @@ -192,7 +201,17 @@ class tui_layout_split : public tui_layout_base void apply (int x, int y, int width, int height) override; - tui_adjust_result set_height (const char *name, int new_height) override; + tui_adjust_result set_height (const char *name, int new_height) override + { + /* Pass false as the final argument to indicate change of height. */ + return set_size (name, new_height, false); + } + + tui_adjust_result set_width (const char *name, int new_width) override + { + /* Pass true as the final argument to indicate change of width. */ + return set_size (name, new_width, true); + } bool top_boxed_p () const override; @@ -217,6 +236,15 @@ class tui_layout_split : public tui_layout_base private: + /* Used to implement set_height and set_width member functions. When + SET_WIDTH_P is true, set the width, otherwise, set the height of the + window named NAME to NEW_SIZE, updating the sizes of the other windows + around it as needed. The result indicates if the window NAME was + found and had its size adjusted, was found but was not adjusted, or + was not found at all. */ + tui_adjust_result set_size (const char *name, int new_size, + bool set_width_p); + /* Set the weights from the current heights (when m_vertical is true) or widths (when m_vertical is false). */ void set_weights_from_sizes (); @@ -266,6 +294,10 @@ extern void tui_apply_current_layout (); extern void tui_adjust_window_height (struct tui_win_info *win, int new_height); +/* Adjust the window width of WIN to NEW_WIDTH. */ +extern void tui_adjust_window_width (struct tui_win_info *win, + int new_width); + /* The type of a function that is used to create a TUI window. */ typedef std::function window_factory; diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index ba6aca3d078..512ea52b694 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")); -- 2.25.4