package notty

  1. Overview
  2. Docs

Fullscreen input and output

.

Notty IO for pure Unix.

This is an IO module for Notty.

module Term : sig ... end

Terminal IO abstraction for fullscreen, interactive applications.

Inline output

These operations do not change the terminal state and do not assume exclusive access to the output. They can be combined with other means of producing output.

val winsize : Unix.file_descr -> (int * int) option

winsize fd is Some (columns, rows), the current dimensions of fd's backing tty, or None, when fd is not backed by a tty.

val output_image : ?cap:Notty.Cap.t -> ?clear:bool -> ?chan:Pervasives.out_channel -> Notty.image -> unit

output_image ~cap ~clear ~chan i writes the image i to chan.

The image is displayed in its full height. If the output is a tty, image width is clipped to the output width, otherwise, full width is used.

~cap is the optional terminal capability set.

~clear repositions the cursor to the beginning of the line and clears is. Otherwise, the output continues from the current position. Defaults to false.

~chan defaults to stdout.

val output_image_size : ?cap:Notty.Cap.t -> ?clear:bool -> ?chan:Pervasives.out_channel -> ((int * int) -> Notty.image) -> unit

output_image_size ~cap ~clear ~chan f is output_image ~cap ~chan (f size) where size are chan's current output dimensions.

If chan is not backed by a tty, as a matter of convenience, f is applied to (80, 24). Use Unix.isatty or winsize to detect whether the output has a well-defined size.

val output_image_endline : ?cap:Notty.Cap.t -> ?clear:bool -> ?chan:Pervasives.out_channel -> Notty.image -> unit

print_image_endline ~cap ~clear ~chan i is output_image ~cap ~chan i followed by a newline.

Capability detection

All image output requires terminal capabilities.

When not provided, capabilities are auto-detected, by checking that the output is a tty, that the environment variable $TERM is set, and that it is not set to either "" or "dumb". If these conditions hold, ANSI escapes are used. Otherwise, no escapes are used.