Explorar el Código

fix scrollback behavior

 1. /r/n of the last printed line must no printed,
    to avoid an additional empty line

 2. the input line on the bottom of the terminal
    have to be substracted from the first scroll
    back jump.
Jan Klemkow hace 6 años
padre
commit
0f993a9704
Se han modificado 1 ficheros con 11 adiciones y 3 borrados
  1. 11 3
      scroll.c

+ 11 - 3
scroll.c

@@ -165,6 +165,7 @@ void
 scrollup(void)
 {
 	int rows;
+	int first = 0;
 
 	/* move the text in terminal n lines down */
 	dprintf(STDOUT_FILENO, "\033[%dS", ws.ws_row);
@@ -172,12 +173,19 @@ scrollup(void)
 	/* set cursor position */
 	write(STDOUT_FILENO, "\033[0;0H", 6);
 
+	if (TAILQ_FIRST(&head) == bottom)
+		first = 1;
+
 	for (rows = 0; bottom != NULL && rows < 2 * ws.ws_row; rows++)
 		bottom = TAILQ_NEXT(bottom, entries);
 
-	for (; bottom != NULL && rows > ws.ws_row; rows--) {
-		bottom = TAILQ_PREV(bottom, tailhead, entries);
-		write(STDOUT_FILENO, bottom->buf, bottom->len);
+	for (; rows > ws.ws_row - first;) {
+		if ((bottom = TAILQ_PREV(bottom, tailhead, entries)) == NULL)
+			break;
+		if (--rows > ws.ws_row - first)
+			write(STDOUT_FILENO, bottom->buf, bottom->size);
+		else /* last line w/o "/r/n" */
+			write(STDOUT_FILENO, bottom->buf, bottom->size - 2);
 	}
 }