diff options
author | Guo Ci <zguoci@gmail.com> | 2017-06-22 11:01:14 +0200 |
---|---|---|
committer | Amadeusz Sławiński <amade@asmblr.net> | 2017-06-22 11:01:14 +0200 |
commit | afa26c59cad2a9f62ecf7898b7bf0e9ac8a82db8 (patch) | |
tree | 72072c733ca3f1020cd242b5bab5f4818d41033e | |
parent | c10e99789904ac687701fb9bd7d2bf8b8995b166 (diff) | |
download | screen-afa26c59cad2a9f62ecf7898b7bf0e9ac8a82db8.tar.gz |
begin viewing scrollback buffer at the first line of output instead of at the start of the scrollback buffer
This issue has been discussed before:
https://bbs.archlinux.org/viewtopic.php?id=108640
Copy mode and “hardcopy -h” always begin at the start of the scrollback buffer.
If a user sets a large scrollback limit with little output, then copy mode and
the file written by “hardcopy -h” will begin with many blank lines before the
first line of output.
The attached patch limits the scrollback buffer traversal to begin at the first
line of output, instead of the beginning of the scrollback buffer.
Also, code for moving to %age of buffer is changed to use float division so
that two different rep_cnt will not jump to the same location, except for
buffers less than 100 lines. Previously, the computed line number is rounded
down to the nearest 100th due to integer division.
Bug: 49377
-rw-r--r-- | src/ansi.c | 2 | ||||
-rw-r--r-- | src/fileio.c | 2 | ||||
-rw-r--r-- | src/mark.c | 9 | ||||
-rw-r--r-- | src/resize.c | 2 | ||||
-rw-r--r-- | src/window.h | 1 |
5 files changed, 12 insertions, 4 deletions
@@ -2906,6 +2906,8 @@ struct mline *ml; if (++wp->w_histidx >= wp->w_histheight) wp->w_histidx = 0; + if (wp->w_scrollback_height < wp->w_histheight) + ++wp->w_scrollback_height; } #endif diff --git a/src/fileio.c b/src/fileio.c index b084edd..14bb9b1 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -458,7 +458,7 @@ void WriteFile(struct acluser *user, char *fn, int dump) { } if (dump == DUMP_SCROLLBACK) { #ifdef COPY_PASTE - for (i = 0; i < fore->w_histheight; i++) { + for (i = fore->w_histheight - fore->w_scrollback_height; i < fore->w_histheight; i++) { p = (char *)(WIN(i)->image); for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--) ; @@ -782,7 +782,10 @@ processchar: rep_cnt = 0; if (rep_cnt > 100) rep_cnt = 100; - revto_line(markdata->left_mar, (rep_cnt * (fore->w_histheight + fore->w_height)) / 100, (fore->w_height - 1) / 2); + revto_line(markdata->left_mar, + fore->w_histheight - fore->w_scrollback_height + + (int)(rep_cnt * (fore->w_scrollback_height + fore->w_height) / 100.0), + (fore->w_height - 1) / 2); break; case 0201: case 'g': @@ -1122,8 +1125,8 @@ int tx, ty, line; tx = 0; else if (tx > fore->w_width - 1) tx = fore->w_width -1; - if (ty < 0) - ty = 0; + if (ty < fore->w_histheight - fore->w_scrollback_height) + ty = fore->w_histheight - fore->w_scrollback_height; else if (ty > fore->w_histheight + fore->w_height - 1) ty = fore->w_histheight + fore->w_height - 1; diff --git a/src/resize.c b/src/resize.c index ba7988d..9790012 100644 --- a/src/resize.c +++ b/src/resize.c @@ -1019,6 +1019,8 @@ int wi, he, hi; /* store new size */ p->w_width = wi; p->w_height = he; + if(p->w_scrollback_height > hi) + p->w_scrollback_height = hi; #ifdef COPY_PASTE p->w_histidx = 0; p->w_histheight = hi; diff --git a/src/window.h b/src/window.h index fa82609..bd10dcd 100644 --- a/src/window.h +++ b/src/window.h @@ -248,6 +248,7 @@ struct win int w_slowpaste; /* do careful writes to the window */ int w_histheight; /* all histbases are malloced with width * histheight */ int w_histidx; /* 0 <= histidx < histheight; where we insert lines */ + int w_scrollback_height; /* number of lines of output stored, to be updated with w_histidx, w_histheight */ struct mline *w_hlines; /* history buffer */ struct paster w_paster; /* paste info */ #else |