Module B0_std.TtySource

ANSI terminal interaction.

Terminals

Sourcetype t = [ `Dumb | `Term of string ] option

The type for terminals. Either no terminal, a dumb one or a named terminal from the TERM environment variable.

Sourceval of_fd : Unix.file_descr -> t

of_fd fd determines the terminal for file descriptor fd by using Unix.isatty fd and consulting the TERM environment variable.

Capabilities

Sourcetype cap = [
  1. | `None
    (*

    No capability.

    *)
  2. | `Ansi
    (*

    ANSI terminal.

    *)
]

The type for terminal capabilities. Either no capability or ANSI capability.

Sourceval cap : t -> cap

cap tty determines tty's capabilities.

ANSI escapes and styling

Sourcetype color = [
  1. | `Default
  2. | `Black
  3. | `Red
  4. | `Green
  5. | `Yellow
  6. | `Blue
  7. | `Magenta
  8. | `Cyan
  9. | `White
]

The type for ANSI colors.

Sourcetype 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.

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

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

Sourceval strip_escapes : string -> string

strip_escapes s removes ANSI escapes from s.