Skip to content

Commit 2de5398

Browse files
Update vendored notty to include OCaml 5.4 support (ocaml#11482)
PR in question is ocaml-dune/notty#10 Signed-off-by: Marek Kubica <[email protected]>
1 parent a60637f commit 2de5398

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

vendor/notty/src-unix/native/winsize.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <caml/mlvalues.h>
22

33
#ifdef _WIN32
4-
#include <caml/fail.h>
4+
#include <windows.h>
55
#else
66
#include <sys/ioctl.h>
77
#include <signal.h>
@@ -15,7 +15,16 @@
1515
CAMLprim value caml_notty_winsize (value vfd) {
1616
#ifdef _WIN32
1717
(void) vfd;
18-
caml_failwith("not implemented on windows");
18+
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
19+
if (hConsole == INVALID_HANDLE_VALUE) return Val_int (0);
20+
21+
CONSOLE_SCREEN_BUFFER_INFO csbi;
22+
if (GetConsoleScreenBufferInfo(hConsole, &csbi)) {
23+
int columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
24+
int rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
25+
return Val_int ((columns << 16) + ((rows & 0x7fff) << 1));
26+
}
27+
return Val_int (0);
1928
#else
2029
int fd = Int_val (vfd);
2130
struct winsize w;

vendor/notty/src/notty.ml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,12 @@ module A = struct
209209
and b x = x land 0xff
210210

211211
let bold = 1
212-
and italic = 2
213-
and dim = 3
214-
and underline = 4
215-
and blink = 8
216-
and reverse = 16
212+
and dim = 2
213+
and faint = 2
214+
and italic = 4
215+
and underline = 8
216+
and blink = 16
217+
and reverse = 32
217218

218219
let empty = { fg = 0; bg = 0; st = 0 }
219220

@@ -384,7 +385,12 @@ module I = struct
384385

385386
let create () =
386387
let img, line, attr = ref empty, ref empty, ref [] in
387-
let fmt = formatter_of_out_functions {
388+
(* OCaml 5.4 added a new record field so to keep compatibility, get and
389+
update the record, even if warning 23 "useless-record-with" is
390+
triggered, about all fields being updated in <5.4. *)
391+
let formatter_out_functions = get_formatter_out_functions () in
392+
let[@warning "-23"] formatter_out_functions = {
393+
formatter_out_functions with
388394
out_flush = (fun () ->
389395
img := !img <-> !line; line := empty; attr := [])
390396
; out_newline = (fun () ->
@@ -394,7 +400,9 @@ module I = struct
394400
(* Not entirely clear; either or both could be void: *)
395401
; out_spaces = (fun w -> line := !line <|> char (top_a attr) ' ' w 1)
396402
; out_indent = (fun w -> line := !line <|> char (top_a attr) ' ' w 1)
397-
} in
403+
}
404+
in
405+
let fmt = formatter_of_out_functions formatter_out_functions in
398406
pp_set_formatter_stag_functions fmt {
399407
(pp_get_formatter_stag_functions fmt ()) with
400408
mark_open_stag =
@@ -511,7 +519,7 @@ module Cap = struct
511519

512520
let ((<|), (<.), (<!)) = Buffer.(add_string, add_char, add_decimal)
513521

514-
let sts = [ ";1"; ";3"; ";4"; ";5"; ";7" ]
522+
let sts = [ ";1"; ";2"; ";3"; ";4"; ";5"; ";7" ]
515523

516524
let sgr { A.fg; bg; st } buf =
517525
buf <| "\x1b[0";

vendor/notty/src/notty.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ module A : sig
138138
(** Additional text properties. *)
139139

140140
val bold : style
141-
val italic : style
142141
val dim : style
142+
val faint : style
143+
val italic : style
143144
val underline : style
144145
val blink : style
145146
val reverse : style

vendor/update-notty.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
version=cb7221c73f8009a904fa249fdeb5558c83043b8f
3+
version=83aad282853bc35564114db72b65a087acf82ccf
44

55
set -e -o pipefail
66

0 commit comments

Comments
 (0)