Fix truncation of TUI command history

Message ID 1420861759-10700-2-git-send-email-patrick@parcs.ath.cx
State New, archived
Headers

Commit Message

Patrick Palka Jan. 10, 2015, 3:49 a.m. UTC
  If we submit a command while the prompt cursor is somewhere other than
at the end of the command line, the command line gets truncated as the
command window gets shifted one line up.  This happens because we fail
to properly move the cursor to the end of the command line before
transmitting the newline to ncurses.  We need to move the cursor because
when ncurses outputs a newline it truncates any text that appears
past the end of the cursor.

The fix is generic enough to work properly even in multi-line secondary
prompts like the quit prompt.

gdb/ChangeLog:

	* tui/tui-io.c (tui_getc): Move cursor to the end of the command
	line before printing a newline.
---
 gdb/tui/tui-io.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
  

Comments

Patrick Palka Jan. 10, 2015, 3:59 a.m. UTC | #1
This is an improved variant of the patch here
https://sourceware.org/ml/gdb-patches/2014-09/msg00109.html that also
works properly for secondary prompts (and overlong lines).
  
Patrick Palka Jan. 26, 2015, 7:15 p.m. UTC | #2
Ping.
  
Patrick Palka Feb. 4, 2015, 2:50 p.m. UTC | #3
Ping.
  
Pedro Alves Feb. 10, 2015, 5:29 p.m. UTC | #4
On 01/10/2015 03:49 AM, Patrick Palka wrote:

> We need to move the cursor because
> when ncurses outputs a newline it truncates any text that appears
> past the end of the cursor.

Can you merge this sentence into the comment in the code?

>        else
>          {
> -          wmove (w, TUI_CMD_WIN->detail.command_info.cur_line,
> -                 TUI_CMD_WIN->detail.command_info.curch);
> -          waddch (w, ch);
> +	  /* Move cursor to the end of the command line before emitting the
> +	     newline.  */

... as this as is doesn't explain _why_ we need to do that, which
may make the reader wonder.

> +	  int px = TUI_CMD_WIN->detail.command_info.curch;
> +	  int py = TUI_CMD_WIN->detail.command_info.cur_line;
> +	  px += rl_end - rl_point;
> +	  py += px / TUI_CMD_WIN->generic.width;
> +	  px %= TUI_CMD_WIN->generic.width;
> +	  wmove (w, py, px);
> +	  waddch (w, ch);
>          }
>      }
>    
> 

OK with that change.  Thanks!

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 73dbcfc..94c3ec2 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -708,9 +708,15 @@  tui_getc (FILE *fp)
         }
       else
         {
-          wmove (w, TUI_CMD_WIN->detail.command_info.cur_line,
-                 TUI_CMD_WIN->detail.command_info.curch);
-          waddch (w, ch);
+	  /* Move cursor to the end of the command line before emitting the
+	     newline.  */
+	  int px = TUI_CMD_WIN->detail.command_info.curch;
+	  int py = TUI_CMD_WIN->detail.command_info.cur_line;
+	  px += rl_end - rl_point;
+	  py += px / TUI_CMD_WIN->generic.width;
+	  px %= TUI_CMD_WIN->generic.width;
+	  wmove (w, py, px);
+	  waddch (w, ch);
         }
     }