(** 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 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. *)