shithub: riscv

Download patch

ref: 03bcc1520a54573c7149233cf51975e0fe077399
parent: b74ce50a1c8670e46ee55c4aa09912da6567bd9b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Sep 27 12:08:51 EDT 2018

vt: fix backup/forward after resize

--- a/sys/src/cmd/vt/cons.h
+++ b/sys/src/cmd/vt/cons.h
@@ -54,7 +54,7 @@
 extern int	number(Rune *, int *);
 extern void	shift(int,int,int,int);
 extern void	scroll(int,int,int,int);
-extern void	backup(int);
+extern int	backup(int);
 extern void	sendnchars(int, char *);
 extern Point	pt(int, int);
 extern Point	pos(Point);
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -58,7 +58,6 @@
 int	x, y;	/* character positions */
 Rune	*backp;
 int	backc;
-int	atend;
 int	nbacklines;
 int	xmax, ymax;
 int	blocked;
@@ -1142,18 +1141,13 @@
 
 	switch(menuhit(2, mc, &menu2, nil)) {
 	case Mbackup:		/* back up */
-		if(atend == 0){
+		if(backup(backc+1))
 			backc++;
-			backup(backc);
-		}
 		return;
 
 	case Mforward:		/* move forward */
-		backc--;
-		if(backc >= 0)
-			backup(backc);
-		else
-			backc = 0;
+		if(backc > 0)
+			backup(--backc);
 		return;
 
 	case Mreset:		/* reset */
@@ -1183,11 +1177,11 @@
 	}
 }
 
-void
+int
 backup(int count)
 {
 	Rune *cp;
-	int n;
+	int left, n;
 
 	unselect();
 
@@ -1200,13 +1194,13 @@
 		nbacklines = ymax-1;
 	}
 	cp = histp;
-	atend = 0;
+	left = 1;
 	while (n >= 0) {
 		cp--;
 		if(cp < hist)
 			cp = &hist[HISTSIZ-1];
 		if(*cp == '\0') {
-			atend = 1;
+			left = 0;
 			break;
 		}
 		if(*cp == '\n')
@@ -1216,6 +1210,7 @@
 	if(cp >= &hist[HISTSIZ])
 		cp = hist;
 	backp = cp;
+	return left;
 }
 
 Point