diff --git a/common/include/villas/terminal.hpp b/common/include/villas/terminal.hpp index e3681adb9..546cccc77 100644 --- a/common/include/villas/terminal.hpp +++ b/common/include/villas/terminal.hpp @@ -33,10 +33,12 @@ namespace villas { class Terminal { protected: - static struct winsize window; /**< Size of the terminal window. */ + struct winsize window; /**< Size of the terminal window. */ bool isTty; + static class Terminal *current; + public: Terminal(); @@ -45,12 +47,18 @@ public: static int getCols() { - return window.ws_col; + if (!current) + current = new Terminal(); + + return current->window.ws_col; } static int getRows() { - return window.ws_row; + if (!current) + current = new Terminal(); + + return current->window.ws_row; } }; diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp index 8f0140788..b5ecf7430 100644 --- a/common/lib/terminal.cpp +++ b/common/lib/terminal.cpp @@ -28,7 +28,7 @@ using namespace villas; -struct winsize Terminal::window; +class Terminal * Terminal::current = nullptr; Terminal::Terminal() { @@ -65,11 +65,11 @@ void Terminal::resize(int, siginfo_t *, void *) { int ret; - ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); + ret = ioctl(STDERR_FILENO, TIOCGWINSZ, ¤t->window); if (ret) throw SystemError("Failed to get terminal dimensions"); Logger logger = logging.get("terminal"); - logger->debug("New terminal size: {}x{}", window.ws_row, window.ws_col); + logger->debug("New terminal size: {}x{}", current->window.ws_row, current->window.ws_col); };