Skip to content

Commit a99d5bb

Browse files
authored
Merge pull request #38 from art-w/sigwinch
Add missing `ocaml_terminal_get_sigwinch` for unsupported platform
2 parents dd1f3cf + 029cbc0 commit a99d5bb

File tree

6 files changed

+25
-40
lines changed

6 files changed

+25
-40
lines changed

src/progress/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
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)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
9499
CAMLprim value ocaml_terminal_get_terminal_dimensions(value unit)
95100
{
96101
CAMLparam1(unit);

src/progress/terminal_width.ml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@
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+
620
let on_change = ref (fun _ -> ())
721
let latest_width = ref None
822

923
let 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

src/terminal/dune

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
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))

src/terminal/terminal.ml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@ module Ansi = Ansi
1010
let 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

src/terminal/terminal.mli

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,6 @@ module Ansi : sig
8080
val erase_display_suffix : string
8181
end
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-
9883
val 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

0 commit comments

Comments
 (0)