mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 10:40:00 +08:00
Add API to set terminal fallback size (#230)
In case of embedded systems, the terminal size may not always be detectable (e.g. in case of serial output). Allow application to set up the default size in case autodetection fails. On platform such as Emscripten, there is only "fallback" size. Signed-off-by: Jarosław Pelczar <jarek@jpelczar.com>
This commit is contained in:
parent
5e199fcd85
commit
7298636e7c
@ -9,6 +9,7 @@ struct Dimensions {
|
||||
|
||||
namespace Terminal {
|
||||
Dimensions Size();
|
||||
void SetFallbackSize(const Dimensions& fallbackSize);
|
||||
|
||||
enum Color {
|
||||
Palette1,
|
||||
|
@ -18,9 +18,18 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
static Dimensions fallback_size{140, 43};
|
||||
#elif defined(_WIN32)
|
||||
// The Microsoft default "cmd" returns errors above.
|
||||
static Dimensions fallback_size{80, 80};
|
||||
#else
|
||||
static Dimensions fallback_size{80, 25};
|
||||
#endif
|
||||
|
||||
Dimensions Terminal::Size() {
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
return Dimensions{140, 43};
|
||||
return fallback_size;
|
||||
#elif defined(_WIN32)
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
|
||||
@ -29,19 +38,24 @@ Dimensions Terminal::Size() {
|
||||
csbi.srWindow.Bottom - csbi.srWindow.Top + 1};
|
||||
}
|
||||
|
||||
// The Microsoft default "cmd" returns errors above.
|
||||
return Dimensions{80, 80};
|
||||
return fallback_size;
|
||||
|
||||
#else
|
||||
winsize w{};
|
||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
||||
if (w.ws_col == 0 || w.ws_row == 0) {
|
||||
return Dimensions{80, 25};
|
||||
return fallback_size;
|
||||
}
|
||||
return Dimensions{w.ws_col, w.ws_row};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// @brief Override terminal size in case auto-detection fails
|
||||
/// @param fallbackSize Terminal dimensions to fallback to
|
||||
void Terminal::SetFallbackSize(const Dimensions& fallbackSize) {
|
||||
fallback_size = fallbackSize;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
const char* Safe(const char* c) {
|
||||
|
Loading…
Reference in New Issue
Block a user