Jochen Sprickerhof 5 лет назад
Родитель
Сommit
8afdc10fd5
1 измененных файлов с 14 добавлено и 7 удалено
  1. 14 7
      scroll.c

+ 14 - 7
scroll.c

@@ -254,16 +254,19 @@ redraw()
 {
 {
 	int rows = 0, x, y;
 	int rows = 0, x, y;
 
 
+	if (bottom == NULL)
+		return;
+
 	getcursorposition(&x, &y);
 	getcursorposition(&x, &y);
 
 
+	if (y < ws.ws_row-1)
+	  y--;
+
 	/* wind back bottom pointer by shown history */
 	/* wind back bottom pointer by shown history */
 	for (; bottom != NULL && TAILQ_NEXT(bottom, entries) != NULL &&
 	for (; bottom != NULL && TAILQ_NEXT(bottom, entries) != NULL &&
-	    rows < y - 2; rows++)
+	    rows < y - 1; rows++)
 		bottom = TAILQ_NEXT(bottom, entries);
 		bottom = TAILQ_NEXT(bottom, entries);
 
 
-	if (rows == 0)
-		return;
-
 	/* clear screen */
 	/* clear screen */
 	dprintf(STDOUT_FILENO, "\033[2J");
 	dprintf(STDOUT_FILENO, "\033[2J");
 	/* set cursor position to upper left corner */
 	/* set cursor position to upper left corner */
@@ -275,12 +278,16 @@ redraw()
 	else
 	else
 		write(STDOUT_FILENO, bottom->buf, bottom->size);
 		write(STDOUT_FILENO, bottom->buf, bottom->size);
 
 
-	for (; rows > 0; rows--) {
+	for (rows = ws.ws_row; rows > 0 &&
+	    TAILQ_PREV(bottom, tailhead, entries) != NULL; rows--) {
 		bottom = TAILQ_PREV(bottom, tailhead, entries);
 		bottom = TAILQ_PREV(bottom, tailhead, entries);
 		write(STDOUT_FILENO, bottom->buf, bottom->size);
 		write(STDOUT_FILENO, bottom->buf, bottom->size);
 	}
 	}
-	/* add new line in front of the shell prompt */
-	write(STDOUT_FILENO, "\n", 1);
+
+	if (bottom == TAILQ_FIRST(&head))
+		write(STDOUT_FILENO, "\n", 1);
+	else
+		bottom = TAILQ_NEXT(bottom, entries);
 }
 }
 
 
 void
 void