summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuo Ci <zguoci@gmail.com>2017-06-21 23:29:50 +0200
committerAmadeusz Sławiński <amade@asmblr.net>2017-06-21 23:29:50 +0200
commit6a2f12c28a677ba814575d42825434bfb970e4e9 (patch)
treee9d9418f4d80001c8a44baa0bf2d5ac1e201b3b2 /src
parentd23b14f9712f213b7e7faed21e9730001c7fe5b4 (diff)
downloadscreen-6a2f12c28a677ba814575d42825434bfb970e4e9.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
Diffstat (limited to 'src')
-rw-r--r--src/ansi.c2
-rw-r--r--src/fileio.c2
-rw-r--r--src/mark.c8
-rw-r--r--src/resize.c2
-rw-r--r--src/window.h1
5 files changed, 11 insertions, 4 deletions
diff --git a/src/ansi.c b/src/ansi.c
index ec70cf3..27efb7e 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -2250,6 +2250,8 @@ static void WAddLineToHist(Window *win, struct mline *ml)
if (++win->w_histidx >= win->w_histheight)
win->w_histidx = 0;
+ if (win->w_scrollback_height < win->w_histheight)
+ ++win->w_scrollback_height;
}
int MFindUsedLine(Window *win, int ye, int ys)
diff --git a/src/fileio.c b/src/fileio.c
index 1f1a83a..caa75e4 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -415,7 +415,7 @@ void WriteFile(struct acluser *user, char *fn, int dump)
fputs("<\n", f);
}
if (dump == DUMP_SCROLLBACK) {
- for (i = 0; i < fore->w_histheight; i++) {
+ for (i = fore->w_histheight - fore->w_scrollback_height; i < fore->w_histheight; i++) {
p = (WIN(i)->image);
pf = WIN(i)->font;
for (k = fore->w_width - 1; k >= 0 && p[k] == ' '; k--) ;
diff --git a/src/mark.c b/src/mark.c
index eed7675..663cd6e 100644
--- a/src/mark.c
+++ b/src/mark.c
@@ -686,7 +686,9 @@ static void MarkProcess(char **inbufp, size_t *inlenp)
rep_cnt = 0;
if (rep_cnt > 100)
rep_cnt = 100;
- revto_line(markdata->left_mar, (rep_cnt * (fore->w_histheight + fore->w_height)) / 100,
+ 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:
@@ -994,8 +996,8 @@ void revto_line(int tx, int ty, int 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 0dc032d..9cec1cf 100644
--- a/src/resize.c
+++ b/src/resize.c
@@ -754,6 +754,8 @@ int ChangeWindowSize(Window *p, int wi, int he, int hi)
/* store new size */
p->w_width = wi;
p->w_height = he;
+ if(p->w_scrollback_height > hi)
+ p->w_scrollback_height = hi;
p->w_histidx = 0;
p->w_histheight = hi;
diff --git a/src/window.h b/src/window.h
index 59b058d..5400b41 100644
--- a/src/window.h
+++ b/src/window.h
@@ -224,6 +224,7 @@ struct Window {
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 */
pid_t w_pid; /* process at the other end of ptyfd */