From patchwork Tue Jun 23 15:29:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7304 Received: (qmail 70286 invoked by alias); 23 Jun 2015 15:30:09 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 70269 invoked by uid 89); 23 Jun 2015 15:30:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f179.google.com Received: from mail-qk0-f179.google.com (HELO mail-qk0-f179.google.com) (209.85.220.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 23 Jun 2015 15:30:01 +0000 Received: by qkbp125 with SMTP id p125so6688015qkb.2 for ; Tue, 23 Jun 2015 08:29:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Yu3F2W5wOgwb2WV9MEXCY/rR9NccCmQK2MdXtfPFjd0=; b=YPvoqRj0V10VAvvfHx6vnxqo+Uluz/qjyjXIjtAHiRwiYmRk2rVHYX9jmFm9IILqfU p8bzSZ+596N21dJYGRqvFYsOT8+TAVMhhaxlb9P1tqiODiw+ceaeGlnQUnDpH/2AYICk Sdp7TZEJa8dIPBsMXpVQS5F5wW+MsVOwxvgX4xdAOYxRwgTuTS9UGrUY3CE4ocNmZGrc UVGLciZHPiSBaWKKsYF6mmTdudsdI098Q8uR2dAsTfzbGahvTIoXskTBFxnYu4h4oyBl Zs4MpyDj5sIRo7BbYpG9g4oWibu5NizX73XBtmSY+Srb3qkyIbWhHDOaGW3IGE5ep3MH CdvQ== X-Gm-Message-State: ALoCoQl8xDN9v5NMxBpqmhlTN1l5/qE58DGlJpIj2IeLaD2HzjnMUbhCGvKKmIJkUgPFiaho1NWm X-Received: by 10.55.26.133 with SMTP id l5mr54481452qkh.40.1435073399367; Tue, 23 Jun 2015 08:29:59 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id w67sm1622658qgw.41.2015.06.23.08.29.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jun 2015 08:29:58 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Add tab completion for TUI's "focus" command Date: Tue, 23 Jun 2015 11:29:51 -0400 Message-Id: <1435073391-18518-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1434943800-9274-1-git-send-email-patrick@parcs.ath.cx> References: <1434943800-9274-1-git-send-email-patrick@parcs.ath.cx> The implementation is pretty straightforward, with the only caveat being that the "src", "cmd", "next" and "prev" entries get delibrately added to the completion list even when the TUI has not yet been initialized (i.e. has never been enabled during the session), since invoking the "focus" command with these arguments already works when the TUI has not yet been initialized. gdb/ChangeLog: * tui/tui-win.c (focus_completer): New static function. (_initialize_tui_win): Set the completion function of the "focus" command to focus_completer. gdb/testsuite/ChangeLog: * gdb.base/completion.exp: Test the completion of the "focus" command. --- gdb/testsuite/gdb.base/completion.exp | 18 +++++++++ gdb/tui/tui-win.c | 69 ++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index 4c31bfc..1eb0fd8 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -878,3 +878,21 @@ if {![skip_tui_tests]} { } } } +if {![skip_tui_tests]} { + with_test_prefix "focus command" { + set test "test completion" + send_gdb "focus \t\t" + gdb_test_multiple "" "$test" { + -re "cmd *next *prev *src *\r\n$gdb_prompt focus $" { + pass "$test" + } + } + send_gdb "\003" + set test "quit command input after testing completion" + gdb_test_multiple "" "$test" { + -re "$gdb_prompt $" { + pass "$test" + } + } + } +} diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c index 8c0685b..feb360b 100644 --- a/gdb/tui/tui-win.c +++ b/gdb/tui/tui-win.c @@ -354,6 +354,71 @@ tui_set_var_cmd (char *null_args, int from_tty, struct cmd_list_element *c) tui_rehighlight_all (); } +/* Complete possible window names to focus on. TEXT is the complete text + entered so far, WORD is the word currently being completed. */ + +static VEC (char_ptr) * +focus_completer (struct cmd_list_element *ignore, + const char *text, const char *word) +{ + VEC (const_char_ptr) *completion_name_vec = NULL; + VEC (char_ptr) *matches_vec; + int win_type; + + for (win_type = SRC_WIN; win_type < MAX_MAJOR_WINDOWS; win_type++) + { + const char *completion_name = NULL; + + /* We can't focus on an invisible window. */ + if (tui_win_list[win_type] == NULL + || !tui_win_list[win_type]->generic.is_visible) + continue; + + switch (win_type) + { + case SRC_WIN: + completion_name = "src"; + break; + case DISASSEM_WIN: + completion_name = "asm"; + break; + case DATA_WIN: + completion_name = "regs"; + break; + case CMD_WIN: + completion_name = "cmd"; + break; + default: + break; + } + + if (completion_name != NULL) + VEC_safe_push (const_char_ptr, completion_name_vec, completion_name); + } + + /* 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. */ + if (VEC_length (const_char_ptr, completion_name_vec) == 0) + { + VEC_safe_push (const_char_ptr, completion_name_vec, "src"); + VEC_safe_push (const_char_ptr, completion_name_vec, "cmd"); + } + + VEC_safe_push (const_char_ptr, completion_name_vec, "next"); + VEC_safe_push (const_char_ptr, completion_name_vec, "prev"); + VEC_safe_push (const_char_ptr, completion_name_vec, NULL); + + matches_vec + = complete_on_enum (VEC_address (const_char_ptr, completion_name_vec), + text, word); + + VEC_free (const_char_ptr, completion_name_vec); + + return matches_vec; +} + /* Function to initialize gdb commands, for tui window manipulation. */ @@ -365,6 +430,7 @@ _initialize_tui_win (void) { static struct cmd_list_element *tui_setlist; static struct cmd_list_element *tui_showlist; + struct cmd_list_element *focus_cmd; /* Define the classes of commands. They will appear in the help list in the reverse of this order. */ @@ -393,7 +459,7 @@ regs : the register display\n")); add_com_alias ("wh", "winheight", class_tui, 0); add_info ("win", tui_all_windows_info, _("List of all displayed windows.\n")); - add_com ("focus", class_tui, tui_set_focus_command, _("\ + focus_cmd = add_com ("focus", class_tui, tui_set_focus_command, _("\ Set focus to named window or next/prev window.\n\ Usage: focus { | next | prev}\n\ Valid Window names are:\n\ @@ -402,6 +468,7 @@ asm : the disassembly window\n\ regs : the register display\n\ cmd : the command window\n")); add_com_alias ("fs", "focus", class_tui, 0); + set_cmd_completer (focus_cmd, focus_completer); add_com ("+", class_tui, tui_scroll_forward_command, _("\ Scroll window forward.\n\ Usage: + [win] [n]\n"));