diff options
author | Jakob P. Liljenberg <admin@qvantnet.com> | 2024-01-03 16:40:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-03 16:40:04 +0100 |
commit | 32b6622cec38aa6caa02111d76186195dcfbe95f (patch) | |
tree | 4a27a7212369425705973fc29f9c8feff00b00ba | |
parent | a29545c4079e9bc5203e09965ac03fabe975bd7e (diff) | |
parent | ef788efc536733a441949dab854b0a6bea5ef33e (diff) |
Merge pull request #627 from imwints/lldb-term-size
-rw-r--r-- | src/btop_tools.cpp | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/btop_tools.cpp b/src/btop_tools.cpp index e17edf8..e6ecbd8 100644 --- a/src/btop_tools.cpp +++ b/src/btop_tools.cpp @@ -26,9 +26,10 @@ tab-size = 4 #include <utility> #include <ranges> -#include <unistd.h> -#include <termios.h> +#include <fcntl.h> #include <sys/ioctl.h> +#include <termios.h> +#include <unistd.h> #include "unordered_map" #include "widechar_width.hpp" @@ -85,12 +86,27 @@ namespace Term { } bool refresh(bool only_check) { - struct winsize w; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) return false; - if (width != w.ws_col or height != w.ws_row) { + // Query dimensions of '/dev/tty' of the 'STDOUT_FILENO' isn't avaiable. + // This variable is set in those cases to avoid calls to ioctl + constinit static bool uses_dev_tty = false; + struct winsize wsize {}; + if (uses_dev_tty || ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsize) < 0 || (wsize.ws_col == 0 && wsize.ws_row == 0)) { + Logger::error(R"(Couldn't determine terminal size of "STDOUT_FILENO"!)"); + auto dev_tty = open("/dev/tty", O_RDONLY); + if (dev_tty != -1) { + ioctl(dev_tty, TIOCGWINSZ, &wsize); + close(dev_tty); + } + else { + Logger::error(R"(Couldn't determine terminal size of "/dev/tty"!)"); + return false; + } + uses_dev_tty = true; + } + if (width != wsize.ws_col or height != wsize.ws_row) { if (not only_check) { - width = w.ws_col; - height = w.ws_row; + width = wsize.ws_col; + height = wsize.ws_row; } return true; } |