Use sensible defaults in case TIOCGWINSZ fails (#224)

This can happen for example in embedded linux, in case
the application is started via serial terminal.

Signed-off-by: Jarosław Pelczar <jarek@jpelczar.com>
Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Jarosław Pelczar
2021-10-09 11:51:00 +02:00
committed by GitHub
parent 31c26c6956
commit 75482d82d4
2 changed files with 7 additions and 1 deletions

View File

@@ -33,8 +33,11 @@ Dimensions Terminal::Size() {
return Dimensions{80, 80};
#else
winsize w;
winsize w{};
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
if (w.ws_col == 0 || w.ws_row == 0) {
return Dimensions{80, 25};
}
return Dimensions{w.ws_col, w.ws_row};
#endif
}