mirror of
https://github.com/aristocratos/btop.git
synced 2024-06-16 17:35:03 +12:00
Merge pull request #627 from imwints/lldb-term-size
This commit is contained in:
commit
32b6622cec
|
@ -26,9 +26,10 @@ tab-size = 4
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "unordered_map"
|
#include "unordered_map"
|
||||||
#include "widechar_width.hpp"
|
#include "widechar_width.hpp"
|
||||||
|
@ -85,12 +86,27 @@ namespace Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool refresh(bool only_check) {
|
bool refresh(bool only_check) {
|
||||||
struct winsize w;
|
// Query dimensions of '/dev/tty' of the 'STDOUT_FILENO' isn't avaiable.
|
||||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) return false;
|
// This variable is set in those cases to avoid calls to ioctl
|
||||||
if (width != w.ws_col or height != w.ws_row) {
|
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) {
|
if (not only_check) {
|
||||||
width = w.ws_col;
|
width = wsize.ws_col;
|
||||||
height = w.ws_row;
|
height = wsize.ws_row;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue