summaryrefslogtreecommitdiff
path: root/lib/terminal.mli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/terminal.mli')
-rw-r--r--lib/terminal.mli67
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/terminal.mli b/lib/terminal.mli
new file mode 100644
index 0000000..0fd11ed
--- /dev/null
+++ b/lib/terminal.mli
@@ -0,0 +1,67 @@
1(** A module to simplify communication with the underlying terminal
2 emulator. *)
3
4open Base
5open Unix
6
7type terminal_size = int * int
8(** Size of the terminal window. *)
9
10type state = {
11 tio : terminal_io; (** Status flags for the terminal window *)
12 size : terminal_size; (** Size of the terminal window *)
13}
14(** Global state of the terminal window. *)
15
16val get_char : unit -> char option
17(** Non-blocking request for a keypress.
18 Use {!val:Terminal.char_stream} for an infinite sequence of input
19 bytes.
20
21 @return A [char] if a key was pressed, nothing otherwise. *)
22
23val char_stream : char option Sequence.t
24(** The infinite stream of input bytes from stdin.
25 Returns [None] if no key was pressed; this is to be able to
26 interpret the absense of a keypress as an action. *)
27
28val write_seq : char Sequence.t -> unit
29(** Write a sequence of strings to standard output.
30
31 @param seq The sequence of strings to output. *)
32
33val restore_screen : unit -> unit
34(** Clear screen and show cursor. Meant to be called on exit. *)
35
36val redraw : char Sequence.t Sequence.t -> int * int -> unit
37(** Redraw the screen, using the provided sequence of lines.
38
39 @param seq A sequence of lines.
40 @param cur Cursor position. *)
41
42val get_state : unit -> state
43(** Get current state for the terminal window *)
44
45val size : unit -> int * int
46(** Compute the current size of the terminal.
47
48 This is done by moving the cursor to the far bottom right position
49 and querying for the cursor position using the appropriate escape
50 sequences.
51
52 @return size of the terminal window in terms of character rows and columns. *)
53
54val enable_raw_mode : terminal_io -> unit -> unit
55(** Turn on raw mode by overriding the correct terminal flags.
56 This is done according to [man 3 termios].
57
58 @param tio The current status of the terminal for [stdin]. *)
59
60val restore_status : terminal_io -> unit -> unit
61(** Override the terminal status.
62
63 @param tio The new terminal status for [stdin]. *)
64
65val init : unit -> state
66(** Turns on raw mode and makes sure to restore the previous terminal
67 status on exit. *)