Module Down_std.Tty

Terminal interaction.

Capabilities

type cap = [
  1. | `None
  2. | `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 = [
  1. | `Default
  2. | `Black
  3. | `Red
  4. | `Green
  5. | `Yellow
  6. | `Blue
  7. | `Magenta
  8. | `Cyan
  9. | `White
]

The type for ANSI colors.

type style = [
  1. | `Bold
  2. | `Faint
  3. | `Italic
  4. | `Underline
  5. | `Reverse
  6. | `Fg of [ color | `Hi of color ]
  7. | `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_hide : string

cursor_hide hides the cursor.

val cursor_show : string

cursor_show shows the cursor.

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 = [
  1. | `Up
  2. | `Down
  3. | `Left
  4. | `Right
]
type input = [
  1. | `Arrow of arrow
  2. | `Backspace
  3. | `Bytes of string
  4. | `Ctrl of [ `Key of int | `Arrow of arrow ]
  5. | `Delete
  6. | `End
  7. | `Enter
  8. | `Escape
  9. | `Function of int
  10. | `Home
  11. | `Meta of int
  12. | `Page of [ `Up | `Down ]
  13. | `Shift of [ `Arrow of arrow ]
  14. | `Tab
  15. | `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.