public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Patrick Palka <patrick@parcs.ath.cx>
To: gdb-patches@sourceware.org
Cc: Patrick Palka <patrick@parcs.ath.cx>
Subject: [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent
Date: Wed, 26 Aug 2015 01:06:00 -0000	[thread overview]
Message-ID: <1440551173-18266-1-git-send-email-patrick@parcs.ath.cx> (raw)

The command window's start_line field is used by the function
tui_redisplay_readline to figure out on which window line to start
redrawing the (possibly multi-line) command line.  It differs from the Y
coordinate of the window cursor only when the length of the line being
outputted is longer than the width of the window.

The function tui_puts however currently does not respect this property
of start_line.  After a call to tui_puts, start_line will always be
equal to cur_line even when the outputted line may have wrapped a few
times.  This patch makes tui_puts update start_line in a way that's
consistent with how tui_redisplay_readline does it.  This patch also
explicitly documents this property of start_line.

gdb/ChangeLog:

	* tui/tui-data.h (tui_command_info): Add comment documenting the
	field start_line.
	* tui/tui-io.c (tui_puts): Fix the updating of start_line.
---
 gdb/tui/tui-data.h |  5 +++++
 gdb/tui/tui-io.c   | 17 ++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index df1fe6c..2f9030a 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -265,6 +265,11 @@ struct tui_source_info
 
 struct tui_command_info
 {
+  /* The line number (i.e. the Y coordinate of the command window) that
+     contains the start of the latest line being outputted.  START_LINE differs
+     from the Y coordinate of the window cursor only when the current line is
+     longer than the width of the window, i.e. only when the current line has
+     wrapped to the next line one or more times.  */
   int start_line;
 };
 
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index c7a092f..311c96c 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -168,7 +168,12 @@ tui_puts (const char *string)
         }
       else if (tui_skip_line != 1)
         {
+	  int prev_line, prev_col;
+
           tui_skip_line = -1;
+
+	  getyx (w, prev_line, prev_col);
+
 	  /* Expand TABs, since ncurses on MS-Windows doesn't.  */
 	  if (c == '\t')
 	    {
@@ -183,11 +188,21 @@ tui_puts (const char *string)
 	    }
 	  else
 	    waddch (w, c);
+
+	  if (c == '\n')
+	    TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
+	  else if (getcurx (w) <= prev_col && getcury (w) == prev_line)
+	    {
+	      /* If the cursor is on the last line of the command window and the
+		 added character caused the line to wrap, then we have to adjust
+		 start_line to compensate for the scrolling up of each line that
+		 the line wrapping caused.  */
+	      TUI_CMD_WIN->detail.command_info.start_line--;
+	    }
         }
       else if (c == '\n')
         tui_skip_line = -1;
     }
-  TUI_CMD_WIN->detail.command_info.start_line = getcury (w);
 }
 
 /* Readline callback.
-- 
2.5.0.417.g69c5dbd.dirty

             reply	other threads:[~2015-08-26  1:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-26  1:06 Patrick Palka [this message]
2015-08-26  1:06 ` [PATCH 2/2] tui: maintain a scrollback buffer and dump it upon exit (PR tui/14584) Patrick Palka
2015-09-10 15:25   ` Pedro Alves
2015-09-10 22:57     ` Patrick Palka
2015-09-11  8:58       ` Pedro Alves
2015-09-10 15:25 ` [PATCH 1/2] tui: make updating of start_line in tui_puts more consistent Pedro Alves

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=1440551173-18266-1-git-send-email-patrick@parcs.ath.cx \
    --to=patrick@parcs.ath.cx \
    --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).