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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -2,6 +2,9 @@
## Current ## Current
## Bug
- On Unix system, fallback to {80,25} screen dimension on failure.
## 0.10 (2021-09-30) ## 0.10 (2021-09-30)
## Bug ## Bug

View File

@ -33,8 +33,11 @@ Dimensions Terminal::Size() {
return Dimensions{80, 80}; return Dimensions{80, 80};
#else #else
winsize w; winsize w{};
ioctl(STDOUT_FILENO, TIOCGWINSZ, &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}; return Dimensions{w.ws_col, w.ws_row};
#endif #endif
} }