sigildocs

(sigil ansi)

(sigil ansi) - ANSI Terminal Escape Codes

Colored and styled terminal output using ANSI escape codes. All functions are prefixed with a: to avoid naming conflicts.

Basic Usage

(import (sigil ansi))

(display (a:green "PASS"))
(display (a:bold (a:red "FAIL")))
(display (a:dim "at test.sgl:42"))

Composing Styles

Styles can be nested for combined effects:

(display (a:bold (a:underline (a:cyan "Important"))))

Cursor Control

(display (a:clear-screen))
(display (a:cursor-position 10 20))  ; row 10, column 20

Disabling Colors

For non-TTY output, disable ANSI codes:

(with-ansi-disabled
  (lambda ()
    (display (a:red "This won't have color"))))

Exports

ansi-enabled?procedure

Check if ANSI codes are currently enabled.

(ansi-enabled?)  ; => #t

Execute a thunk with ANSI codes disabled.

Useful when outputting to files or non-TTY streams.

(with-ansi-disabled
  (lambda ()
    (a:red "text")))  ; => "text" (no escape codes)
ansi-wrapprocedure

Wrap text with ANSI code, or return plain text if disabled

a:blackprocedure

Apply black foreground color.

a:redprocedure

Apply red foreground color.

a:greenprocedure

Apply green foreground color.

a:yellowprocedure

Apply yellow foreground color.

a:blueprocedure

Apply blue foreground color.

a:magentaprocedure

Apply magenta foreground color.

a:cyanprocedure

Apply cyan foreground color.

a:whiteprocedure

Apply white foreground color.

Apply bright black (gray) foreground color.

a:bright-redprocedure

Apply bright red foreground color.

Apply bright green foreground color.

Apply bright yellow foreground color.

a:bright-blueprocedure

Apply bright blue foreground color.

Apply bright magenta foreground color.

a:bright-cyanprocedure

Apply bright cyan foreground color.

Apply bright white foreground color.

a:bg-blackprocedure

Apply black background color.

a:bg-redprocedure

Apply red background color.

a:bg-greenprocedure

Apply green background color.

a:bg-yellowprocedure

Apply yellow background color.

a:bg-blueprocedure

Apply blue background color.

a:bg-magentaprocedure

Apply magenta background color.

a:bg-cyanprocedure

Apply cyan background color.

a:bg-whiteprocedure

Apply white background color.

a:boldprocedure

Apply bold text style.

a:dimprocedure

Apply dim (faint) text style.

a:italicprocedure

Apply italic text style.

a:underlineprocedure

Apply underline text style.

a:inverseprocedure

Apply inverse (swap foreground/background) text style.

a:hiddenprocedure

Apply hidden text style.

Apply strikethrough text style.

a:resetprocedure

Reset all text attributes.

Clear the entire screen and move cursor to home position.

(display (a:clear-screen))
a:clear-lineprocedure

Clear current line

a:cursor-upprocedure

Move cursor up N lines

a:cursor-downprocedure

Move cursor down N lines

Move cursor forward N columns

a:cursor-backprocedure

Move cursor back N columns

a:cursor-homeprocedure

Move cursor to home position (1,1)

Move cursor to specific position (row, col) - 1-indexed

a:hide-cursorprocedure

Hide cursor

a:show-cursorprocedure

Show cursor

a:save-cursorprocedure

Save cursor position

Restore cursor position

strip-ansiprocedure

Remove all ANSI escape codes from a string.

Useful for computing display width or writing to files.

(strip-ansi (a:red "hello"))  ; => "hello"