Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions include/indicators/terminal_size.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ static inline size_t terminal_width() { return terminal_size().second; }

#else

#include <sys/ioctl.h> //ioctl() and TIOCGWINSZ
#include <unistd.h> // for STDOUT_FILENO
#include <fcntl.h> // open and O_RDWR
#include <sys/ioctl.h> // ioctl() and TIOCGWINSZ
#include <unistd.h> // close

namespace indicators {

static inline std::pair<size_t, size_t> 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_t>(size.ws_row), static_cast<size_t>(size.ws_col)};
}

Expand Down
11 changes: 8 additions & 3 deletions single_include/indicators/indicators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,14 +975,19 @@ static inline size_t terminal_width() { return terminal_size().second; }

#else

#include <sys/ioctl.h> //ioctl() and TIOCGWINSZ
#include <unistd.h> // for STDOUT_FILENO
#include <fcntl.h> // open and O_RDWR
#include <sys/ioctl.h> // ioctl() and TIOCGWINSZ
#include <unistd.h> // close

namespace indicators {

static inline std::pair<size_t, size_t> 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_t>(size.ws_row), static_cast<size_t>(size.ws_col)};
}

Expand Down