Module Down_std.Tty

Terminal interaction.

Capabilities

type cap = [
| `None
| `Ansi
]

The type for capabilities.

val cap : cap

cap is the current terminal capability. This only uses environment variables to detect it.

ANSI Styling

type color = [
| `Default
| `Black
| `Red
| `Green
| `Yellow
| `Blue
| `Magenta
| `Cyan
| `White
]

The type for ANSI colors.

type style = [
| `Bold
| `Faint
| `Italic
| `Underline
| `Reverse
| `Fg of [ color | `Hi of color ]
| `Bg of [ color | `Hi of color ]
]

The type for ANSI styles.

val styled_str : cap -> style list -> string -> string

styled_str cap styles s is s styled according to cap and styles.

Output

val output : string -> unit

output s outputs s on stdout and flushes it.

val ding : string

ding rings the bell.

val newline : string

newline is CRLF.

val clear_row : string

clear_row erases the row.

val cursor_up : int -> string

cursor_up n moves up n rows.

val cursor_down : int -> string

cursor_down n moves down n rowns.

val cursor_forward : int -> string

cursor_forward n moves cursor by n columns.

val cursor_origin : string

cursor_origin moves cursor to the top-left origin.

val clear_screen : string

clear_screen clears the screen.

Input

type arrow = [
| `Up
| `Down
| `Left
| `Right
]
type input = [
| `Arrow of arrow
| `Backspace
| `Bytes of string
| `Ctrl of [ `Key of int | `Arrow of arrow ]
| `Delete
| `End
| `Enter
| `Escape
| `Function of int
| `Home
| `Meta of int
| `Page of [ `Up | `Down ]
| `Shift of [ `Arrow of arrow ]
| `Tab
| `Unknown of string
]

The type for user input.

val input : (unit -> int option) -> input option

input readc is user input read byte-by-byte using readc.

val pp_input : Stdlib.Format.formatter -> input -> unit

pp_input formats inputs.

Width

val width : (unit -> int option) -> int

width readc tries to termine the tty width using output and readc to read the result.