From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 06/15] gdb/tui: better filtering of tab completion results for focus command
Date: Fri, 6 Jan 2023 10:25:33 +0000 [thread overview]
Message-ID: <c9c92af8205d35dcbc34964200ec16502f040eae.1673000632.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1673000632.git.aburgess@redhat.com>
While working on the previous couple of commits, I noticed that the
'focus' command would happily suggest 'status' as a possible focus
completion, even though the 'status' window is non-focusable, and,
after the previous couple of commits, trying to focus the status
window will result in an error.
This commit improves the tab-completion results for the focus command
so that the status window is not included.
---
gdb/testsuite/gdb.tui/completion.exp | 18 ++++++++++++++++--
gdb/testsuite/gdb.tui/tui-focus.exp | 4 +---
gdb/tui/tui-win.c | 24 +++++++++++++++++-------
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/gdb/testsuite/gdb.tui/completion.exp b/gdb/testsuite/gdb.tui/completion.exp
index 00956488c9f..1d7de65abb7 100644
--- a/gdb/testsuite/gdb.tui/completion.exp
+++ b/gdb/testsuite/gdb.tui/completion.exp
@@ -13,8 +13,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-gdb_exit
-gdb_start
+tuiterm_env
+
+clean_restart
if {[skip_tui_tests] || [target_info exists gdb,nointerrupts]} {
return
@@ -54,3 +55,16 @@ with_test_prefix "completion of layout names" {
with_test_prefix "completion of focus command" {
test_tab_completion "focus" "cmd *next *prev *src *"
}
+
+# Now run some completion tests when TUI mode is enabled.
+Term::clean_restart 24 80
+if {![Term::prepare_for_tui]} {
+ unsupported "TUI not supported"
+ return
+}
+
+Term::command "layout src"
+Term::command "complete focus "
+Term::dump_screen
+Term::check_region_contents "check focus completions" 0 17 80 5 \
+ "focus cmd\\s*focus next\\s*focus prev\\s*focus src\\s*$gdb_prompt"
diff --git a/gdb/testsuite/gdb.tui/tui-focus.exp b/gdb/testsuite/gdb.tui/tui-focus.exp
index 156ced44e05..0563aacd0a2 100644
--- a/gdb/testsuite/gdb.tui/tui-focus.exp
+++ b/gdb/testsuite/gdb.tui/tui-focus.exp
@@ -33,8 +33,7 @@ if {[skip_tui_tests]} {
# Each test specification is a tuple where the first item is the name of a
# window, and the second item is a boolean indicating if we expect that
# window to be present in the default (src) layout.
-##foreach spec {{src true} {cmd true} {status true} {regs false} {asm false}} {}
-foreach spec {{status false}} {
+foreach spec {{src true} {cmd true} {status false} {regs false} {asm false}} {
lassign $spec window valid_p
with_test_prefix "window=$window" {
@@ -60,7 +59,6 @@ foreach spec {{status false}} {
}
Term::check_box "check src box" 0 0 80 15
-
Term::command "focus prev"
}
}
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 4fc8e7a4503..492a5191025 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -362,13 +362,19 @@ show_tui_resize_message (struct ui_file *file, int from_tty,
\f
/* Generic window name completion function. Complete window name pointed
- to by TEXT and WORD. If INCLUDE_NEXT_PREV_P is true then the special
- window names 'next' and 'prev' will also be considered as possible
- completions of the window name. */
+ to by TEXT and WORD.
+
+ If EXCLUDE_CANNOT_FOCUS_P is true, then windows that can't take focus
+ will be excluded from the completions, otherwise they will be included.
+
+ If INCLUDE_NEXT_PREV_P is true then the special window names 'next' and
+ 'prev' will also be considered as possible completions of the window
+ name. This is independent of EXCLUDE_CANNOT_FOCUS_P. */
static void
window_name_completer (completion_tracker &tracker,
- int include_next_prev_p,
+ bool include_next_prev_p,
+ bool exclude_cannot_focus_p,
const char *text, const char *word)
{
std::vector<const char *> completion_name_vec;
@@ -377,10 +383,14 @@ window_name_completer (completion_tracker &tracker,
{
const char *completion_name = NULL;
- /* We can't focus on an invisible window. */
+ /* Don't include an invisible window. */
if (!win_info->is_visible ())
continue;
+ /* If requested, exclude windows that can't be focused. */
+ if (exclude_cannot_focus_p && !win_info->can_focus ())
+ continue;
+
completion_name = win_info->name ();
gdb_assert (completion_name != NULL);
completion_name_vec.push_back (completion_name);
@@ -415,7 +425,7 @@ focus_completer (struct cmd_list_element *ignore,
completion_tracker &tracker,
const char *text, const char *word)
{
- window_name_completer (tracker, 1, text, word);
+ window_name_completer (tracker, true, true, text, word);
}
/* Complete possible window names for winheight command. TEXT is the
@@ -432,7 +442,7 @@ winheight_completer (struct cmd_list_element *ignore,
if (word != text)
return;
- window_name_completer (tracker, 0, text, word);
+ window_name_completer (tracker, false, false, text, word);
}
/* Update gdb's knowledge of the terminal size. */
--
2.25.4
next prev parent reply other threads:[~2023-01-06 10:26 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-06 10:25 [PATCH 00/15] Mixed bag of TUI tests and fixes Andrew Burgess
2023-01-06 10:25 ` [PATCH 01/15] gdb/testsuite: extend gdb.tui/tui-layout.exp test script Andrew Burgess
2023-01-25 11:29 ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 02/15] gdb/testsuite: update gdb.tui/tui-disasm-long-lines.exp Andrew Burgess
2023-01-25 11:29 ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 03/15] gdb/testsuite: update gdb.tui/tui-nl-filtered-output.exp Andrew Burgess
2023-01-25 11:30 ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 04/15] gdb/testsuite/tui: more testing of the 'focus' command Andrew Burgess
2023-01-25 11:32 ` Andrew Burgess
2023-01-06 10:25 ` [PATCH 05/15] gdb/tui: convert if/error to an assert Andrew Burgess
2023-01-25 11:33 ` Andrew Burgess
2023-01-06 10:25 ` Andrew Burgess [this message]
2023-01-25 11:33 ` [PATCH 06/15] gdb/tui: better filtering of tab completion results for focus command Andrew Burgess
2023-01-06 10:25 ` [PATCH 07/15] gdb/testsuite: fix line feed scrolling in tuiterm.exp Andrew Burgess
2023-01-06 10:25 ` [PATCH 08/15] gdb/tui: improve errors from tui focus command Andrew Burgess
2023-01-06 10:25 ` [PATCH 09/15] gdb/tui: disable tui mode when an assert triggers Andrew Burgess
2023-01-06 10:25 ` [PATCH 10/15] gdb/tui: make m_horizontal_offset private Andrew Burgess
2023-01-06 10:25 ` [PATCH 11/15] gdb/tui: rewrite of tui_source_window_base to handle very long lines Andrew Burgess
2023-01-06 10:25 ` [PATCH 12/15] gdb/tui: avoid extra refresh_window on horizontal scroll Andrew Burgess
2023-01-06 10:25 ` [PATCH 13/15] gdb/tui: avoid extra refresh_window on vertical scroll Andrew Burgess
2023-01-06 10:25 ` [PATCH 14/15] gdb/tui: more debug output Andrew Burgess
2023-01-06 10:25 ` [PATCH 15/15] gdb/tui: make use of a scoped_restore Andrew Burgess
2023-01-25 12:01 ` Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 0/8] Mixed bag of TUI tests and fixes Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 1/8] gdb/testsuite: fix line feed scrolling in tuiterm.exp Andrew Burgess
2023-01-25 19:46 ` Tom Tromey
2023-01-25 12:08 ` [PATCHv2 2/8] gdb/tui: improve errors from tui focus command Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 3/8] gdb/tui: disable tui mode when an assert triggers Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 4/8] gdb/tui: make m_horizontal_offset private Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 5/8] gdb/tui: rewrite of tui_source_window_base to handle very long lines Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 6/8] gdb/tui: avoid extra refresh_window on horizontal scroll Andrew Burgess
2023-01-25 20:05 ` Tom Tromey
2023-01-25 12:08 ` [PATCHv2 7/8] gdb/tui: avoid extra refresh_window on vertical scroll Andrew Burgess
2023-01-25 12:08 ` [PATCHv2 8/8] gdb/tui: more debug output Andrew Burgess
2023-01-25 20:07 ` [PATCHv2 0/8] Mixed bag of TUI tests and fixes Tom Tromey
2023-01-27 16:31 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c9c92af8205d35dcbc34964200ec16502f040eae.1673000632.git.aburgess@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).