Files
Tart/source/term.c

46 lines
1.1 KiB
C
Raw Normal View History

2025-01-29 10:51:20 -08:00
#include "term.h"
2025-01-29 14:46:08 -08:00
// if windows is defined.
2025-01-29 15:10:36 -08:00
#if defined(_WIN64) || defined(_WIN32)
2025-01-29 10:51:20 -08:00
#include <Windows.h>
struct tart_vec2 term_current_size() {
struct tart_vec2 ret;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
unsigned int rows = (csbi.srWindow.Right - csbi.srWindow.Left + 1);
unsigned int cols = (csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
unsigned short max_short = 0XFFFF;
if(rows < max_short && cols < max_short) {
ret = (struct tart_vec2){(unsigned short) rows ,(unsigned short) cols};
}
return ret;
}
2025-01-29 15:10:36 -08:00
#else
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
2025-01-29 15:10:36 -08:00
struct tart_vec2 term_current_size() {
struct tart_vec2 ret;
struct winsize w;
2025-01-29 15:10:36 -08:00
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
unsigned int rows = w.ws_col;
unsigned int cols = w.ws_row;
2025-01-29 15:10:36 -08:00
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