Commit 1322beeb authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

terminal: fix detection of window size

parent 8c4ad25b
......@@ -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;
}
};
......
......@@ -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, &current->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);
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment