Skip to content

Commit e41291b

Browse files
smemshlauft
authored andcommitted
helper: try $COLUMNS if getTerminalWidth() fails, before using 80
this lets the user give the terminal width instead of always defaulting to 80 just because no terminal is detected, and should work with terminals because termios are used first as before and 80 are fallback if $COLUMNS no set. Signed-off-by: Scott Mcdermott <scott@smemsh.net>
1 parent f41b520 commit e41291b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/helper.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,15 @@ int getTerminalWidth ()
528528
terminalWidth = ts.ws_col;
529529
#endif
530530

531+
if (terminalWidth == 0)
532+
{
533+
char *columns = getenv ("COLUMNS");
534+
if (columns != NULL)
535+
{
536+
terminalWidth = atoi (columns);
537+
}
538+
}
539+
531540
return terminalWidth > 0 ? terminalWidth : 80;
532541
}
533542

0 commit comments

Comments
 (0)