terminal
nimony/lib/std/terminal.nim
This module contains a few procedures to control the terminal (also called console). It uses ANSI escape sequences. This is a trimmed port for Nimony of Nim's std/terminal. Windows support is intentionally limited to ANSI output on modern terminals; the legacy console API is not wrapped.
const fgPrefix: stringconst bgPrefix: stringconst ansiResetCode: stringconst stylePrefix: stringtype Style = HoleyEnumfunc dollar`.Style(e: Style): stringtype ForegroundColor = HoleyEnumfunc dollar`.ForegroundColor(e: ForegroundColor): stringtype BackgroundColor = HoleyEnumfunc dollar`.BackgroundColor(e: BackgroundColor): stringtype TerminalCmd = enum resetStyle = (0, "resetStyle") fgColor = (1, "fgColor") bgColor = (2, "bgColor")
func dollar`.TerminalCmd(e: TerminalCmd): stringproc ansiStyleCode(style: int64): stringproc ansiStyleCode(style: Style): stringproc ansiForegroundColorCode(fg: ForegroundColor; bright: bool): stringproc ansiBackgroundColorCode(bg: BackgroundColor; bright: bool): stringproc resetAttributes(f: ref FileObj)Resets all attributes.
proc setStyle(f: ref FileObj; style: Style)Sets a single terminal style attribute.
proc setStyle(f: ref FileObj; style: set[Style])Sets the terminal style.
proc setForegroundColor(f: ref FileObj; fg: ForegroundColor; bright: bool)Sets the terminal's foreground color.
proc setBackgroundColor(f: ref FileObj; bg: BackgroundColor; bright: bool)Sets the terminal's background color.
proc isatty(f: ref FileObj): boolReturns true if
fis associated with a terminal device.proc styledEchoProcessArg(f: ref FileObj; s: string)proc styledEchoProcessArg(f: ref FileObj; c: char)proc styledEchoProcessArg(f: ref FileObj; style: Style)proc styledEchoProcessArg(f: ref FileObj; style: set[Style])proc styledEchoProcessArg(f: ref FileObj; color: ForegroundColor)proc styledEchoProcessArg(f: ref FileObj; color: BackgroundColor)proc styledEchoProcessArg(f: ref FileObj; cmd: TerminalCmd)template styledWrite(f: ref FileObj; vanon: varargs)Similar to
write, but treating terminal style arguments specially. When an argument isStyle,set[Style],ForegroundColor,BackgroundColororTerminalCmdthe corresponding terminal style proc is called instead of writing the value directly.template styledWriteLine(f: ref FileObj; vanon: varargs)Calls
styledWriteand appends a newline at the end.