]> git.lizzy.rs Git - linenoise.git/commitdiff
Fix line editing when columns unavailable
authorSteve Bennett <steveb@workware.net.au>
Thu, 17 Mar 2011 06:39:06 +0000 (16:39 +1000)
committerSteve Bennett <steveb@workware.net.au>
Fri, 8 Apr 2011 01:48:05 +0000 (11:48 +1000)
Sometimes TIOCGWINSZ succeeds but returns columns=0
This makes line editing work rather badly.

If this occurs, just behave as though TIOCGWINSZ had failed
and assume 80 columns.

Signed-off-by: Steve Bennett <steveb@workware.net.au>
linenoise.c

index 4a62b482cf516caedb4aa4a05083f5ab47850e0e..9c84a129e380dc0233cbf68a4ce6a08bf3ae8ab2 100644 (file)
@@ -197,7 +197,7 @@ static void linenoiseAtExit(void) {
 static int getColumns(void) {
     struct winsize ws;
 
-    if (ioctl(1, TIOCGWINSZ, &ws) == -1) return 80;
+    if (ioctl(1, TIOCGWINSZ, &ws) == -1 || ws.ws_col == 0) return 80;
     return ws.ws_col;
 }