blob: cf8f61d9cf5d1e0b082a1bec13680bdcfeccfcf0 (
plain) (
blame)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
(** A module to simplify communication with the underlying terminal
emulator. *)
open Base
open Unix
type terminal_size = int * int
(** Size of the terminal window. *)
type state = {
tio : terminal_io; (** Status flags for the terminal window *)
size : terminal_size; (** Size of the terminal window *)
}
(** Global state of the terminal window. *)
val fmt_reset : char Sequence.t
(** Escape sequence: reset text formatting *)
val fmt_bold_on : char Sequence.t
(** Escape sequence: turn on bold text*)
val fmt_bold_off : char Sequence.t
(** Escape sequence: turn off bold text*)
val fmt_underline : char Sequence.t
(** Escape sequence: underlined text*)
val fmt_blink : char Sequence.t
(** Escape sequence: blinking text*)
val fmt_inverted_on : char Sequence.t
(** Escape sequence: turn on inverted text*)
val fmt_inverted_off : char Sequence.t
(** Escape sequence: turn off inverted text*)
val get_char : unit -> char option
(** Non-blocking request for a keypress.
Use {!val:Terminal.char_stream} for an infinite sequence of input
bytes.
@return A [char] if a key was pressed, nothing otherwise. *)
val char_stream : char option Sequence.t
(** The infinite stream of input bytes from stdin.
Returns [None] if no key was pressed; this is to be able to
interpret the absense of a keypress as an action. *)
val write_seq : char Sequence.t -> unit
(** Write a sequence of strings to standard output.
@param seq The sequence of strings to output. *)
val restore_screen : unit -> unit
(** Clear screen and show cursor. Meant to be called on exit. *)
val redraw : char Sequence.t Sequence.t -> int * int -> unit
(** Redraw the screen, using the provided sequence of lines.
@param seq A sequence of lines.
@param cur Cursor position. *)
val get_state : unit -> state
(** Get current state for the terminal window *)
val size : unit -> int * int
(** Compute the current size of the terminal.
This is done by moving the cursor to the far bottom right position
and querying for the cursor position using the appropriate escape
sequences.
@return size of the terminal window in terms of character rows and columns. *)
val enable_raw_mode : terminal_io -> unit -> unit
(** Turn on raw mode by overriding the correct terminal flags.
This is done according to [man 3 termios].
@param tio The current status of the terminal for [stdin]. *)
val restore_status : terminal_io -> unit -> unit
(** Override the terminal status.
@param tio The new terminal status for [stdin]. *)
val init : unit -> state
(** Turns on raw mode and makes sure to restore the previous terminal
status on exit. *)
|