diff --git a/include/indicators/terminal_size.hpp b/include/indicators/terminal_size.hpp index 0d03077..bf82c9f 100644 --- a/include/indicators/terminal_size.hpp +++ b/include/indicators/terminal_size.hpp @@ -24,14 +24,19 @@ static inline size_t terminal_width() { return terminal_size().second; } #else -#include //ioctl() and TIOCGWINSZ -#include // for STDOUT_FILENO +#include // open and O_RDWR +#include // ioctl() and TIOCGWINSZ +#include // close namespace indicators { static inline std::pair terminal_size() { struct winsize size{}; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); + int fd = open("/dev/tty", O_RDWR); + if (fd >= 0) { + ioctl(fd, TIOCGWINSZ, &size); + close(fd); + } return {static_cast(size.ws_row), static_cast(size.ws_col)}; } diff --git a/single_include/indicators/indicators.hpp b/single_include/indicators/indicators.hpp index 3832d66..b8b053c 100644 --- a/single_include/indicators/indicators.hpp +++ b/single_include/indicators/indicators.hpp @@ -975,14 +975,19 @@ static inline size_t terminal_width() { return terminal_size().second; } #else -#include //ioctl() and TIOCGWINSZ -#include // for STDOUT_FILENO +#include // open and O_RDWR +#include // ioctl() and TIOCGWINSZ +#include // close namespace indicators { static inline std::pair terminal_size() { struct winsize size{}; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); + int fd = open("/dev/tty", O_RDWR); + if (fd >= 0) { + ioctl(fd, TIOCGWINSZ, &size); + close(fd); + } return {static_cast(size.ws_row), static_cast(size.ws_col)}; }