From patchwork Thu Jan 8 03:50:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 4561 Received: (qmail 17827 invoked by alias); 8 Jan 2015 03:51:07 -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 17802 invoked by uid 89); 8 Jan 2015 03:51:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mail-qc0-f179.google.com Received: from mail-qc0-f179.google.com (HELO mail-qc0-f179.google.com) (209.85.216.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 08 Jan 2015 03:51:02 +0000 Received: by mail-qc0-f179.google.com with SMTP id c9so297304qcz.10 for ; Wed, 07 Jan 2015 19:51:00 -0800 (PST) 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; bh=laOGgkbB2qqijbTfo5mzx7w992OGa3qyofVD7H/Sbak=; b=CnIMtihgqKbILYTtnT/t8pBESrlPrDLbtz1XWeq5Yl7nwpNDHauLc8yKJdLFlZrCfn dHXdZK0P8PrfWZcRrO1KYAtj07yJmwARm1XJT4tMnYQkYmNeJoX75Li2eal7gOZu90WZ DWUlWEA3w3l+425nS5zYX0m0k9zRl6Y3IbZsmBuoVORkuJcofCs33HRdREJGTEiVNdwA BeoqrsZ0E43FZ+R2p1XvTR9sbtuf7hWqJ/gRe+14LZQcrpAuLOupy5+iSS6JiiaD0jJH DgCmYZ0HK2rMvhr7J/qawDrmRlSDOzUsNEGPVGNcRQPsbZZBliKlwUe63ALQzU+3uX++ ZvQw== X-Gm-Message-State: ALoCoQmHPzuMZ0g+Lff6SNtclVJKrlBqqy8DRUYWZsxb4klH8hqz7pqq/R3dSEURtaggr8M5d7M0 X-Received: by 10.224.43.202 with SMTP id x10mr11183532qae.16.1420689060027; Wed, 07 Jan 2015 19:51:00 -0800 (PST) Received: from localhost.localdomain (ool-4353ac94.dyn.optonline.net. [67.83.172.148]) by mx.google.com with ESMTPSA id 43sm3017226qgb.17.2015.01.07.19.50.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 07 Jan 2015 19:50:59 -0800 (PST) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] TUI: rewrite tui_query_hook() Date: Wed, 7 Jan 2015 22:50:48 -0500 Message-Id: <1420689048-23538-1-git-send-email-patrick@parcs.ath.cx> This patch rewrites tui_query_hook() to print things via tui_puts() and to read in a line of input via wgetnstr(). The main motivation for this rewrite is to get the backspace key to work correctly during a quit prompt so that the user can revise their answer before pressing enter. The backspace key now works correctly because we now use getstr() instead of successive calls to getch(). gdb/ChangeLog: * tui/tui-hooks.c (tui_query_hook): Rewrite to use tui_puts and wgetnstr. --- gdb/tui/tui-hooks.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index 6ba6285..9dee840 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -68,9 +68,9 @@ tui_query_hook (const char *msg, va_list argp) { int retval; int ans2; - int answer; char *question; struct cleanup *old_chain; + WINDOW *win = TUI_CMD_WIN->generic.handle; /* Format the question outside of the loop, to avoid reusing ARGP. */ @@ -80,30 +80,18 @@ tui_query_hook (const char *msg, va_list argp) echo (); while (1) { - wrap_here (""); /* Flush any buffered output. */ - gdb_flush (gdb_stdout); + char response[2], answer; - fputs_filtered (question, gdb_stdout); - printf_filtered (_("(y or n) ")); + tui_puts (question); + tui_puts (_("(y or n) ")); - wrap_here (""); - gdb_flush (gdb_stdout); - - answer = tui_getc (stdin); - clearerr (stdin); /* in case of C-d */ - if (answer == EOF) /* C-d */ + if (wgetnstr (win, response, 1) == ERR) { retval = 1; break; } - /* Eat rest of input line, to EOF or newline. */ - if (answer != '\n') - do - { - ans2 = tui_getc (stdin); - clearerr (stdin); - } - while (ans2 != EOF && ans2 != '\n' && ans2 != '\r'); + + answer = response[0]; if (answer >= 'a') answer -= 040; @@ -117,10 +105,13 @@ tui_query_hook (const char *msg, va_list argp) retval = 0; break; } - printf_filtered (_("Please answer y or n.\n")); + tui_puts (_("Please answer y or n.\n")); } noecho (); + /* Update our knowledge of the cursor position. */ + tui_puts (""); + do_cleanups (old_chain); return retval; }