No matching definitions.

tur/term

stdlib/term.tur

terminal utilities: size, tty detection, raw mode, ANSI colors.

Since: Phase B1

defn

term/width

(term/width :int)

return the terminal column width.

Number of columns, or 80 as a fallback if ioctl fails.

(term/width)  ; => 80

Since: Phase B2

defn

term/height

(term/height :int)

return the terminal row height.

Number of rows, or 24 as a fallback if ioctl fails.

(term/height)  ; => 24

Since: Phase B2

defn

term/is-tty?

(term/is-tty? [fd :int] :bool)

test whether a file descriptor refers to a terminal.

fdfile descriptor (0=stdin, 1=stdout, 2=stderr)

true if fd is connected to a terminal.

(term/is-tty? 1)  ; => true when stdout is a tty

Since: Phase B2

defn

term/set-raw

(term/set-raw [fd :int] :int)

put a terminal into raw mode (no line buffering or echo).

fdfile descriptor of the terminal

0 on success, -1 on error.

(term/set-raw 0)  ; => 0

Since: Phase B2

defn

term/set-cooked

(term/set-cooked [fd :int] :int)

restore a terminal to cooked (canonical) mode.

fdfile descriptor of the terminal

0 on success, -1 on error.

(term/set-cooked 0)  ; => 0

Since: Phase B2

defn

term/bold

(term/bold [s :cstr] :cstr)

wrap a string in ANSI bold codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI bold, or a plain copy if not a tty or NO_COLOR is set. The caller must free.

(term/bold "hello")  ; => "\x1b[1mhello\x1b[0m"

Since: Phase B2

defn

term/dim

(term/dim [s :cstr] :cstr)

wrap a string in ANSI dim codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI dim, or a plain copy. Caller must free.

(term/dim "note")  ; => "\x1b[2mnote\x1b[0m"

Since: Phase B2

defn

term/red

(term/red [s :cstr] :cstr)

wrap a string in ANSI red foreground codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI red, or a plain copy. Caller must free.

(term/red "error")  ; => "\x1b[31merror\x1b[0m"

Since: Phase B2

defn

term/green

(term/green [s :cstr] :cstr)

wrap a string in ANSI green foreground codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI green, or a plain copy. Caller must free.

(term/green "ok")  ; => "\x1b[32mok\x1b[0m"

Since: Phase B2

defn

term/yellow

(term/yellow [s :cstr] :cstr)

wrap a string in ANSI yellow foreground codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI yellow, or a plain copy. Caller must free.

(term/yellow "warn")  ; => "\x1b[33mwarn\x1b[0m"

Since: Phase B2

defn

term/blue

(term/blue [s :cstr] :cstr)

wrap a string in ANSI blue foreground codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI blue, or a plain copy. Caller must free.

(term/blue "info")  ; => "\x1b[34minfo\x1b[0m"

Since: Phase B2

defn

term/cyan

(term/cyan [s :cstr] :cstr)

wrap a string in ANSI cyan foreground codes.

sNUL-terminated cstr

Heap-allocated cstr with ANSI cyan, or a plain copy. Caller must free.

(term/cyan "debug")  ; => "\x1b[36mdebug\x1b[0m"

Since: Phase B2