1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

terminal: fix detection of window size

This commit is contained in:
Steffen Vogel 2019-01-22 16:02:27 +01:00
parent b4afe74da7
commit c619b48a9d
2 changed files with 14 additions and 6 deletions

View file

@ -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;
}
};

View file

@ -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);
};