From a3a392ceaadcefcc036ff18b0ef5d37f0fc0903f Mon Sep 17 00:00:00 2001 From: PreacherDHM Date: Wed, 29 Jan 2025 15:10:36 -0800 Subject: [PATCH] added term_get_current_size() --- source/term.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/term.c b/source/term.c index 3e35b61..1098a2a 100644 --- a/source/term.c +++ b/source/term.c @@ -4,6 +4,7 @@ // if windows is defined. +#if defined(_WIN64) || defined(_WIN32) #include struct tart_vec2 term_current_size() { struct tart_vec2 ret; @@ -20,3 +21,24 @@ struct tart_vec2 term_current_size() { return ret; } +#else +#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 short max_short = 0XFFFF; + if(rows < max_short && cols < max_short) { + + ret = (struct tart_vec2){(unsigned short) rows ,(unsigned short) cols}; + } + + return ret; +} +#endif