1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Mode = C.Types.TTY.Mode
type t = [ `TTY ] Stream.t
let init ?loop file =
let tty = Stream.allocate C.Types.TTY.t in
C.Functions.TTY.init (Loop.or_default loop) tty (File.to_int file) 0
|> Error.to_result tty
let set_mode tty mode =
C.Functions.TTY.set_mode tty mode
|> Error.to_result ()
let reset_mode () =
C.Functions.TTY.reset_mode ()
|> Error.to_result ()
let get_winsize tty =
let width = Ctypes.(allocate int) 0 in
let height = Ctypes.(allocate int) 0 in
C.Functions.TTY.get_winsize tty width height
|> Error.to_result_lazy (fun () -> Ctypes.(!@ width, !@ height))
module Vterm_state = C.Types.TTY.Vterm_state
let set_vterm_state =
C.Functions.TTY.set_vterm_state
let get_vterm_state () =
let state = Ctypes.allocate_n C.Types.TTY.Vterm_state.t ~count:1 in
C.Functions.TTY.get_vterm_state state
|> Error.to_result_lazy (fun () -> Ctypes.(!@) state)