This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] TUI: rewrite tui_query_hook()
- From: Patrick Palka <patrick at parcs dot ath dot cx>
- To: gdb-patches at sourceware dot org
- Cc: Patrick Palka <patrick at parcs dot ath dot cx>
- Date: Wed, 7 Jan 2015 22:50:48 -0500
- Subject: [PATCH] TUI: rewrite tui_query_hook()
- Authentication-results: sourceware.org; auth=none
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;
}
--
2.2.1.212.gc5b9256