2020-08-16 14:20:12 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
2020-08-19 12:27:26 +03:00
|
|
|
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
2022-09-21 13:13:15 +03:00
|
|
|
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
|
2020-08-19 12:27:26 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void idris2_setupTerm() {
|
2022-09-21 13:13:15 +03:00
|
|
|
HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
DWORD outmode = 0;
|
|
|
|
GetConsoleMode(stdout_handle, &outmode);
|
|
|
|
outmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
|
|
|
SetConsoleMode(stdout_handle, outmode);
|
2020-08-19 12:27:26 +03:00
|
|
|
}
|
|
|
|
|
2020-08-16 14:20:12 +03:00
|
|
|
int idris2_getTermCols() {
|
2022-09-21 13:13:15 +03:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2023-08-02 18:13:40 +03:00
|
|
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
|
|
|
|
return (int)csbi.srWindow.Right - csbi.srWindow.Left + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2020-08-16 14:20:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int idris2_getTermLines() {
|
2022-09-21 13:13:15 +03:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2023-08-02 18:13:40 +03:00
|
|
|
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
|
|
|
|
return (int)csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2020-08-16 14:20:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2020-08-19 12:27:26 +03:00
|
|
|
void idris2_setupTerm() {
|
2022-09-21 13:13:15 +03:00
|
|
|
// NOTE: Currently not needed for non windows systems
|
2020-08-19 12:27:26 +03:00
|
|
|
}
|
|
|
|
|
2020-08-16 14:20:12 +03:00
|
|
|
int idris2_getTermCols() {
|
2022-09-21 13:13:15 +03:00
|
|
|
struct winsize ts;
|
2023-07-18 17:42:47 +03:00
|
|
|
int err = ioctl(0, TIOCGWINSZ, &ts);
|
|
|
|
if (err) {
|
|
|
|
err = ioctl(1, TIOCGWINSZ, &ts);
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
return 0;
|
2022-09-21 13:13:15 +03:00
|
|
|
return (int)ts.ws_col;
|
2020-08-16 14:20:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int idris2_getTermLines() {
|
2022-09-21 13:13:15 +03:00
|
|
|
struct winsize ts;
|
2023-07-18 17:42:47 +03:00
|
|
|
int err = ioctl(0, TIOCGWINSZ, &ts);
|
|
|
|
if (err) {
|
|
|
|
err = ioctl(1, TIOCGWINSZ, &ts);
|
|
|
|
}
|
|
|
|
if (err)
|
|
|
|
return 0;
|
2022-09-21 13:13:15 +03:00
|
|
|
return (int)ts.ws_row;
|
2020-08-16 14:20:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|