(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 20Disabling Colors
For non-TTY output, disable ANSI codes:
(with-ansi-disabled
(lambda ()
(display (a:red "This won't have color"))))Exports
ansi-enabled?procedureCheck if ANSI codes are currently enabled.
(ansi-enabled?) ; => #twith-ansi-disabledprocedureExecute 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-wrapprocedureWrap text with ANSI code, or return plain text if disabled
a:blackprocedureApply black foreground color.
a:redprocedureApply red foreground color.
a:greenprocedureApply green foreground color.
a:yellowprocedureApply yellow foreground color.
a:blueprocedureApply blue foreground color.
a:magentaprocedureApply magenta foreground color.
a:cyanprocedureApply cyan foreground color.
a:whiteprocedureApply white foreground color.
a:bright-blackprocedureApply bright black (gray) foreground color.
a:bright-redprocedureApply bright red foreground color.
a:bright-greenprocedureApply bright green foreground color.
a:bright-yellowprocedureApply bright yellow foreground color.
a:bright-blueprocedureApply bright blue foreground color.
a:bright-magentaprocedureApply bright magenta foreground color.
a:bright-cyanprocedureApply bright cyan foreground color.
a:bright-whiteprocedureApply bright white foreground color.
a:bg-blackprocedureApply black background color.
a:bg-redprocedureApply red background color.
a:bg-greenprocedureApply green background color.
a:bg-yellowprocedureApply yellow background color.
a:bg-blueprocedureApply blue background color.
a:bg-magentaprocedureApply magenta background color.
a:bg-cyanprocedureApply cyan background color.
a:bg-whiteprocedureApply white background color.
a:boldprocedureApply bold text style.
a:dimprocedureApply dim (faint) text style.
a:italicprocedureApply italic text style.
a:underlineprocedureApply underline text style.
a:blinkprocedureApply blinking text style.
a:inverseprocedureApply inverse (swap foreground/background) text style.
a:strikethroughprocedureApply strikethrough text style.
a:resetprocedureReset all text attributes.
a:clear-screenprocedureClear the entire screen and move cursor to home position.
(display (a:clear-screen))a:clear-lineprocedureClear current line
a:cursor-upprocedureMove cursor up N lines
a:cursor-downprocedureMove cursor down N lines
a:cursor-forwardprocedureMove cursor forward N columns
a:cursor-backprocedureMove cursor back N columns
a:cursor-homeprocedureMove cursor to home position (1,1)
a:cursor-positionprocedureMove cursor to specific position (row, col) - 1-indexed
a:hide-cursorprocedureHide cursor
a:show-cursorprocedureShow cursor
a:save-cursorprocedureSave cursor position
a:restore-cursorprocedureRestore cursor position
strip-ansiprocedureRemove all ANSI escape codes from a string.
Useful for computing display width or writing to files.
(strip-ansi (a:red "hello")) ; => "hello"