From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/terminalsize/terminalsize_linux.c | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/detection/terminalsize/terminalsize_linux.c (limited to 'src/detection/terminalsize/terminalsize_linux.c') diff --git a/src/detection/terminalsize/terminalsize_linux.c b/src/detection/terminalsize/terminalsize_linux.c new file mode 100644 index 0000000..e06f958 --- /dev/null +++ b/src/detection/terminalsize/terminalsize_linux.c @@ -0,0 +1,38 @@ +#include "terminalsize.h" +#include "common/io.h" + +#include +#include +#include + +#ifdef __sun + #include +#endif + +bool ffDetectTerminalSize(FFTerminalSizeResult* result) { + struct winsize winsize = {}; + static int ttyfd = STDOUT_FILENO; + if (!isatty(ttyfd)) { + ttyfd = open("/dev/tty", O_RDWR | O_NOCTTY | O_CLOEXEC); + } + + ioctl(ttyfd, TIOCGWINSZ, &winsize); + + if (winsize.ws_row == 0 || winsize.ws_col == 0) { + ffGetTerminalResponse("\e[18t", 2, "\e[8;%hu;%hut", &winsize.ws_row, &winsize.ws_col); + } + + if (winsize.ws_ypixel == 0 || winsize.ws_xpixel == 0) { + ffGetTerminalResponse("\e[14t", 2, "\e[4;%hu;%hut", &winsize.ws_ypixel, &winsize.ws_xpixel); + } + + if (winsize.ws_row == 0 && winsize.ws_col == 0) { + return false; + } + + result->rows = winsize.ws_row; + result->columns = winsize.ws_col; + result->width = winsize.ws_xpixel; + result->height = winsize.ws_ypixel; + return true; +} -- cgit v1.2.3