Library
Module
Module type
Parameter
Class
Class type
Terminal IO abstraction for fullscreen, interactive applications.
This module provides both input and output. It assumes exclusive ownership of the IO streams between initialization and shutdown.
val create :
?dispose:bool ->
?mouse:bool ->
?input:Unix.file_descr ->
?output:Unix.file_descr ->
unit ->
t
create ~dispose ~mouse ~input ~output ()
creates a fresh terminal. It has the following side effects:
Unix.tcsetattr
is applied to input
to disable echo and canonical mode.output
is set to alternate screen mode, the cursor is hidden, and mouse reporting is enabled, using the appropriate control sequences.SIGWINCH
signal, normally ignored, is handled.~dispose
arranges for automatic cleanup of the terminal before the process terminates. The downside is that a reference to this terminal is retained until the program exits. Defaults to true
.
~mouse
activates mouse reporting. Defaults to true
.
~input
is the input file descriptor. Defaults to stdin
.
~output
is the output file descriptor. Defaults to stdout
.
val release : t -> unit
Dispose of this terminal. Original behavior of input is reinstated, cursor is restored, mouse reporting disabled, and alternate mode is terminated.
It is an error to use the commands on a released terminal, and will raise Invalid_argument
, while release
itself is idempotent.
val image : t -> Notty.image -> unit
image t i
sets i
as t
's current image and redraws the terminal.
val refresh : t -> unit
refresh t
redraws the terminal using the current image.
Useful if the output might have become garbled.
val cursor : t -> (int * int) option -> unit
cursor t pos
sets and redraws the cursor.
None
hides it. Some (x, y)
places it at column x
and row y
, with the origin at (1, 1)
, mapping to the upper-left corner.
val input : t -> [ Notty.Unescape.event | `Resize of int * int | `End ]
Wait for new input. input t
can be:
#Unescape.event
, an event
from the input fd;`End
if the input fd is closed, or the terminal was released; or`Resize (cols * rows)
giving the current size of the output tty, if a SIGWINCH
was delivered before or during this call to input
.Note input
is buffered. Calls can either block or immediately return. Use pending
to detect when the next call would not block.
val pending : t -> bool
pending t
is true
if the next call to input
would not block and the terminal has not yet been released.
val size : t -> int * int
size t
is the current size of the terminal's output tty.
module Winch : sig ... end
Manual SIGWINCH
handling.