Skip to content

Commit

Permalink
feature: Windows support for winsize (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Caglayan <[email protected]>
  • Loading branch information
Alizter authored Oct 2, 2023
1 parent 58061ba commit bb4ab8e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src-unix/native/winsize.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <caml/mlvalues.h>

#ifdef _WIN32
#include <caml/fail.h>
#include <windows.h>
#else
#include <sys/ioctl.h>
#include <signal.h>
Expand All @@ -15,7 +15,16 @@
CAMLprim value caml_notty_winsize (value vfd) {
#ifdef _WIN32
(void) vfd;
caml_failwith("not implemented on windows");
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE) return Val_int (0);

CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(hConsole, &csbi)) {
int columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
int rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
return Val_int ((columns << 16) + ((rows & 0x7fff) << 1));
}
return Val_int (0);
#else
int fd = Int_val (vfd);
struct winsize w;
Expand Down

0 comments on commit bb4ab8e

Please sign in to comment.