From 81d664f45e1f165f66ffa48a9d82e087fe904a9e Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Wed, 29 Jan 2025 23:29:15 +0000 Subject: [PATCH] fixed linux implementation and added test --- source/term.c | 11 ++++++----- testing/test_term.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/term.c b/source/term.c index 1098a2a..e82c0dd 100644 --- a/source/term.c +++ b/source/term.c @@ -1,6 +1,4 @@ #include "term.h" -#include "../includes/tart.h" - // if windows is defined. @@ -23,16 +21,19 @@ struct tart_vec2 term_current_size() { } #else #include +#include +#include struct tart_vec2 term_current_size() { struct tart_vec2 ret; - unsigned int rows = w.ws_row; - unsigned int cols = w.ws_col; - struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + unsigned int rows = w.ws_col; + unsigned int cols = w.ws_row; + unsigned short max_short = 0XFFFF; if(rows < max_short && cols < max_short) { diff --git a/testing/test_term.cpp b/testing/test_term.cpp index fbbd596..963a34a 100644 --- a/testing/test_term.cpp +++ b/testing/test_term.cpp @@ -1,4 +1,11 @@ + +#if defined(_WIN64) || defined(_WIN32) #include +#else +#include +#include +#include +#endif #include #include "test_term.h" void term_run(struct pickle_shelf* shelf) { @@ -8,11 +15,21 @@ void term_run(struct pickle_shelf* shelf) { CREATEJAR(Test_Term); PICKLE(Test_get_window_size) { +#if defined(_WIN64) || defined(_WIN32) CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); int columns = (unsigned int)(csbi.srWindow.Right - csbi.srWindow.Left + 1); int rows = (unsigned int)(csbi.srWindow.Bottom - csbi.srWindow.Top + 1); +#else + struct winsize w; + + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + unsigned int rows = w.ws_row; + unsigned int columns = w.ws_col; +#endif std::cout << "\n"; std::cout << term_current_size().x << "term_current_size()\n";