File tree Expand file tree Collapse file tree 6 files changed +25
-40
lines changed
Expand file tree Collapse file tree 6 files changed +25
-40
lines changed Original file line number Diff line number Diff line change 11(library
22 (name progress)
33 (public_name progress)
4+ (foreign_stubs
5+ (language c)
6+ (names terminal_stubs))
47 (libraries
58 (re_export progress.engine)
69 (re_export terminal)
Original file line number Diff line number Diff line change @@ -91,6 +91,11 @@ CAMLprim value ocaml_terminal_get_terminal_dimensions(value unit)
9191// Unsupported platform
9292#else
9393
94+ CAMLprim value ocaml_terminal_get_sigwinch ()
95+ {
96+ return Val_int (0 );
97+ }
98+
9499CAMLprim value ocaml_terminal_get_terminal_dimensions (value unit )
95100{
96101 CAMLparam1 (unit );
Original file line number Diff line number Diff line change 33 Distributed under the MIT license. See terms at the end of this file.
44 ————————————————————————————————————————————————————————————————————————————*)
55
6+ external sigwinch : unit -> int option = " ocaml_terminal_get_sigwinch"
7+ (* * The number of the signal used to indicate terminal size changes. [None] on
8+ Windows. *)
9+
10+ type dimensions = { rows : int ; columns : int }
11+
12+ external get_dimensions : unit -> dimensions option
13+ = " ocaml_terminal_get_terminal_dimensions"
14+
15+ let get_columns () =
16+ match get_dimensions () with
17+ | Some { columns; _ } -> Some columns
18+ | None -> None
19+
620let on_change = ref (fun _ -> () )
721let latest_width = ref None
822
923let initialise =
1024 let handle_signal _ =
11- let width = Terminal.Size. get_columns () in
25+ let width = get_columns () in
1226 latest_width := width;
1327 ! on_change width
1428 in
1529 lazy
16- (latest_width := Terminal.Size. get_columns () ;
17- match Terminal.Size. sigwinch with
30+ (latest_width := get_columns () ;
31+ match sigwinch () with
1832 | None -> ()
1933 | Some n -> Sys. set_signal n (Signal_handle handle_signal))
2034
Original file line number Diff line number Diff line change 11(library
22 (name terminal)
33 (public_name terminal)
4- (foreign_stubs
5- (language c)
6- (names terminal_stubs))
74 (libraries stdlib-shims uutf uucp))
Original file line number Diff line number Diff line change @@ -10,25 +10,6 @@ module Ansi = Ansi
1010let guess_printed_width, truncate_to_width =
1111 Ansi. (guess_printed_width, truncate_to_width)
1212
13- module Size = struct
14- type dimensions = { rows : int ; columns : int }
15-
16- external sigwinch : unit -> int option = " ocaml_terminal_get_sigwinch"
17-
18- external get_dimensions : unit -> dimensions option
19- = " ocaml_terminal_get_terminal_dimensions"
20-
21- let get_rows () =
22- match get_dimensions () with Some { rows; _ } -> Some rows | None -> None
23-
24- let get_columns () =
25- match get_dimensions () with
26- | Some { columns; _ } -> Some columns
27- | None -> None
28-
29- let sigwinch = sigwinch ()
30- end
31-
3213(* ————————————————————————————————————————————————————————————————————————————
3314 Copyright (c) 2020–2021 Craig Ferguson <me@craigfe.io>
3415
Original file line number Diff line number Diff line change @@ -80,21 +80,6 @@ module Ansi : sig
8080 val erase_display_suffix : string
8181end
8282
83- module Size : sig
84- val sigwinch : int option
85- (* * The number of the signal used to indicate terminal size changes. [None] on
86- Windows. *)
87-
88- (* * Functions for getting the size of the terminal to which [stdout] is
89- attached (provided [stdout] is a TTY). *)
90-
91- type dimensions = { rows : int ; columns : int }
92-
93- val get_dimensions : unit -> dimensions option
94- val get_columns : unit -> int option
95- val get_rows : unit -> int option
96- end
97-
9883val guess_printed_width : string -> int
9984(* * [guess_printed_width s] returns an estimate of the number of terminal
10085 columns that the UTF-8 encoded string [s] would occupy if displayed in a
You can’t perform that action at this time.
0 commit comments