Explorar o código

fix die() on too fast scroll input

Jan Klemkow %!s(int64=5) %!d(string=hai) anos
pai
achega
47f9a83aaf
Modificáronse 1 ficheiros con 5 adicións e 6 borrados
  1. 5 6
      scroll.c

+ 5 - 6
scroll.c

@@ -226,12 +226,11 @@ getcursorposition(int *x, int *y)
 	if (write(STDOUT_FILENO, "\033[6n", 4) < 0)
 	if (write(STDOUT_FILENO, "\033[6n", 4) < 0)
 		die("requesting cursor position");
 		die("requesting cursor position");
 
 
-	if ((n = read(STDIN_FILENO, input, sizeof(input)-1)) < 0)
-		die("reading cursor position");
-	input[n] = '\0';
-
-	if (sscanf(input, "\033[%d;%dR", x, y) != 2)
-		die("parsing cursor position: %s", input);
+	do {
+		if ((n = read(STDIN_FILENO, input, sizeof(input)-1)) < 0)
+			die("reading cursor position");
+		input[n] = '\0';
+	} while (sscanf(input, "\033[%d;%dR", x, y) != 2);
 
 
 	if (x <= 0 || y <= 0)
 	if (x <= 0 || y <= 0)
 		die("invalid cursor position: x=%d y=%d", x, y);
 		die("invalid cursor position: x=%d y=%d", x, y);