From 25e607ebf4ebf4c9a52c3a8ee8da9cb6926f500a Mon Sep 17 00:00:00 2001 From: Marek Kubica Date: Fri, 14 Feb 2025 13:59:07 +0100 Subject: [PATCH] Update vendored notty to include OCaml 5.4 support PR in question is https://github.com/ocaml-dune/notty/pull/10 Signed-off-by: Marek Kubica --- vendor/notty/src-unix/native/winsize.c | 13 +++++++++++-- vendor/notty/src/notty.ml | 24 ++++++++++++++++-------- vendor/notty/src/notty.mli | 3 ++- vendor/update-notty.sh | 2 +- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/vendor/notty/src-unix/native/winsize.c b/vendor/notty/src-unix/native/winsize.c index efdc6312881..e6efc84eb07 100644 --- a/vendor/notty/src-unix/native/winsize.c +++ b/vendor/notty/src-unix/native/winsize.c @@ -1,7 +1,7 @@ #include #ifdef _WIN32 -#include +#include #else #include #include @@ -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; diff --git a/vendor/notty/src/notty.ml b/vendor/notty/src/notty.ml index e102145c961..3592bcdf76c 100644 --- a/vendor/notty/src/notty.ml +++ b/vendor/notty/src/notty.ml @@ -209,11 +209,12 @@ module A = struct and b x = x land 0xff let bold = 1 - and italic = 2 - and dim = 3 - and underline = 4 - and blink = 8 - and reverse = 16 + and dim = 2 + and faint = 2 + and italic = 4 + and underline = 8 + and blink = 16 + and reverse = 32 let empty = { fg = 0; bg = 0; st = 0 } @@ -384,7 +385,12 @@ module I = struct let create () = let img, line, attr = ref empty, ref empty, ref [] in - let fmt = formatter_of_out_functions { + (* OCaml 5.4 added a new record field so to keep compatibility, get and + update the record, even if warning 23 "useless-record-with" is + triggered, about all fields being updated in <5.4. *) + let formatter_out_functions = get_formatter_out_functions () in + let[@warning "-23"] formatter_out_functions = { + formatter_out_functions with out_flush = (fun () -> img := !img <-> !line; line := empty; attr := []) ; out_newline = (fun () -> @@ -394,7 +400,9 @@ module I = struct (* Not entirely clear; either or both could be void: *) ; out_spaces = (fun w -> line := !line <|> char (top_a attr) ' ' w 1) ; out_indent = (fun w -> line := !line <|> char (top_a attr) ' ' w 1) - } in + } + in + let fmt = formatter_of_out_functions formatter_out_functions in pp_set_formatter_stag_functions fmt { (pp_get_formatter_stag_functions fmt ()) with mark_open_stag = @@ -511,7 +519,7 @@ module Cap = struct let ((<|), (<.), (