This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
44
unikernel/duniverse/dune_/vendor/notty/src-unix/native/winsize.c
vendored
Normal file
44
unikernel/duniverse/dune_/vendor/notty/src-unix/native/winsize.c
vendored
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <caml/mlvalues.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
/* On some platforms, ioctl() is declared in <unistd.h>. */
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
CAMLprim value caml_notty_winsize (value vfd) {
|
||||
#ifdef _WIN32
|
||||
(void) vfd;
|
||||
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;
|
||||
if (ioctl (fd, TIOCGWINSZ, &w) >= 0)
|
||||
return Val_int ((w.ws_col << 16) + ((w.ws_row & 0x7fff) << 1));
|
||||
return Val_int (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
CAMLprim value caml_notty_winch_number (value vunit) {
|
||||
(void) vunit;
|
||||
#ifdef _WIN32
|
||||
return Val_int (0);
|
||||
#else
|
||||
return Val_int (SIGWINCH);
|
||||
#endif
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue