terminal_style/colors

Search:
Group by:
Source   Edit  

Terminal colors, text attributes, and composable styles.

All helpers return strings and have no terminal or global-state side effects.

Types

ColorPlane = enum
  cpForeground, cpBackground
Selects whether a color affects text or its background. Source   Edit  
TerminalColor = object
  kind*: TerminalColorKind
  index*: uint8
  red*, green*, blue*: uint8

A foreground or background color supported by modern terminals.

Components not used by kind remain zero. A regular object is used instead of a case object so color values remain safe in sequences and closure captures across all supported Nim 2.x compilers.

Source   Edit  
TerminalColorKind = enum
  tckDefault, tckAnsi16, tckAnsi256, tckRgb
Encoding used by a TerminalColor. Source   Edit  
TerminalStyle = object
  foreground*: TerminalColor
  background*: TerminalColor
  attributes*: set[TextAttribute]
A reusable foreground, background, and attribute combination. Source   Edit  
TextAttribute = enum
  taBold, taDim, taItalic, taUnderline, taBlink, taRapidBlink, taReverse,
  taConceal, taStrikethrough, taOverline
Independently composable SGR text attributes. Source   Edit  

Consts

colorBlack = (kind: tckAnsi16, index: 0'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBlue = (kind: tckAnsi16, index: 4'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBrightBlack = (kind: tckAnsi16, index: 8'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBrightBlue = (kind: tckAnsi16, index: 12'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBrightCyan = (kind: tckAnsi16, index: 14'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBrightGreen = (kind: tckAnsi16, index: 10'u, red: 0'u, green: 0'u,
                    blue: 0'u)
Source   Edit  
colorBrightMagenta = (kind: tckAnsi16, index: 13'u, red: 0'u, green: 0'u,
                      blue: 0'u)
Source   Edit  
colorBrightRed = (kind: tckAnsi16, index: 9'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorBrightWhite = (kind: tckAnsi16, index: 15'u, red: 0'u, green: 0'u,
                    blue: 0'u)
Source   Edit  
colorBrightYellow = (kind: tckAnsi16, index: 11'u, red: 0'u, green: 0'u,
                     blue: 0'u)
Source   Edit  
colorCyan = (kind: tckAnsi16, index: 6'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorDefault = (kind: tckDefault, index: 0'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorGreen = (kind: tckAnsi16, index: 2'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorMagenta = (kind: tckAnsi16, index: 5'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorRed = (kind: tckAnsi16, index: 1'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorWhite = (kind: tckAnsi16, index: 7'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
colorYellow = (kind: tckAnsi16, index: 3'u, red: 0'u, green: 0'u, blue: 0'u)
Source   Edit  
termBgBlack = "\e[40m"
Source   Edit  
termBgBlue = "\e[44m"
Source   Edit  
termBgBrightBlack = "\e[100m"
Source   Edit  
termBgBrightBlue = "\e[104m"
Source   Edit  
termBgBrightCyan = "\e[106m"
Source   Edit  
termBgBrightGreen = "\e[102m"
Source   Edit  
termBgBrightMagenta = "\e[105m"
Source   Edit  
termBgBrightRed = "\e[101m"
Source   Edit  
termBgBrightWhite = "\e[107m"
Source   Edit  
termBgBrightYellow = "\e[103m"
Source   Edit  
termBgCyan = "\e[46m"
Source   Edit  
termBgGreen = "\e[42m"
Source   Edit  
termBgMagenta = "\e[45m"
Source   Edit  
termBgRed = "\e[41m"
Source   Edit  
termBgWhite = "\e[47m"
Source   Edit  
termBgYellow = "\e[43m"
Source   Edit  
termBlack = "\e[30m"
Source   Edit  
termBlue = "\e[34m"
Source   Edit  
termBold = "\e[1m"
Source   Edit  
termBrightBlack = "\e[90m"
Source   Edit  
termBrightBlue = "\e[94m"
Source   Edit  
termBrightCyan = "\e[96m"
Source   Edit  
termBrightGreen = "\e[92m"
Source   Edit  
termBrightMagenta = "\e[95m"
Source   Edit  
termBrightRed = "\e[91m"
Source   Edit  
termBrightWhite = "\e[97m"
Source   Edit  
termBrightYellow = "\e[93m"
Source   Edit  
termClear = "\e[0m"
Source   Edit  
termConceal = "\e[8m"
Source   Edit  
termCyan = "\e[36m"
Source   Edit  
termDim = "\e[2m"
Source   Edit  
termGreen = "\e[32m"
Source   Edit  
termHidden = "\e[8m"
Source   Edit  
termItalic = "\e[3m"
Source   Edit  
termMagenta = "\e[35m"
Source   Edit  
termNegative = "\e[7m"
Source   Edit  
termOverline = "\e[53m"
Source   Edit  
termRed = "\e[31m"
Source   Edit  
termReverse = "\e[7m"
Source   Edit  
termStrikethrough = "\e[9m"
Source   Edit  
termUnderline = "\e[4m"
Source   Edit  
termWhite = "\e[37m"
Source   Edit  
termYellow = "\e[33m"
Source   Edit  

Procs

proc `==`(left, right: TerminalColor): bool {....raises: [], tags: [], forbids: [].}
Compares colors by encoding and component values. Source   Edit  
proc ansi16Color(index: range[0 .. 15]): TerminalColor {....raises: [], tags: [],
    forbids: [].}
Constructs one of the 16 standard terminal colors. Source   Edit  
proc ansiCode(attribute: TextAttribute): string {....raises: [], tags: [],
    forbids: [].}
Returns the SGR escape sequence for one text attribute. Source   Edit  
proc ansiCode(color: TerminalColor; plane = cpForeground): string {....raises: [],
    tags: [], forbids: [].}
Returns an SGR escape sequence for color and plane. Source   Edit  
proc ansiCode(textStyle: TerminalStyle): string {....raises: [], tags: [],
    forbids: [].}
Returns one combined SGR sequence for all configured style properties. Source   Edit  
proc applyStyle(value: string; textStyle: TerminalStyle; enabled = true): string {.
    ...raises: [], tags: [], forbids: [].}
Applies textStyle. Disabling it also removes existing ANSI controls. Source   Edit  
proc background(color: TerminalColor; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies an arbitrary background color. Source   Edit  
proc bgBlack(values`gensym23: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBlue(values`gensym27: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc bgBrightBlack(values`gensym31: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightBlue(values`gensym35: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightCyan(values`gensym37: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightGreen(values`gensym33: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightMagenta(values`gensym36: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightRed(values`gensym32: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightWhite(values`gensym38: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgBrightYellow(values`gensym34: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgCyan(values`gensym29: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc bgGreen(values`gensym25: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgMagenta(values`gensym28: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgRed(values`gensym24: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc bgWhite(values`gensym30: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc bgYellow(values`gensym26: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc black(values`gensym7: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc blue(values`gensym11: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc bold(values`gensym39: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc brightBlack(values`gensym15: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightBlue(values`gensym19: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightCyan(values`gensym21: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightGreen(values`gensym17: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightMagenta(values`gensym20: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightRed(values`gensym16: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightWhite(values`gensym22: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc brightYellow(values`gensym18: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc conceal(values`gensym47: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc cyan(values`gensym13: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc dim(values`gensym40: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc foreground(color: TerminalColor; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies an arbitrary foreground color. Source   Edit  
proc green(values`gensym9: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc hexColor(value: string): TerminalColor {....raises: [ValueError], tags: [],
    forbids: [].}
Parses #RGB, RGB, #RRGGBB, or RRGGBB as true color. Source   Edit  
proc hidden(values`gensym48: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc indexed(index: range[0 .. 255]; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies an ANSI-256 foreground color. Source   Edit  
proc indexedColor(index: range[0 .. 255]): TerminalColor {....raises: [], tags: [],
    forbids: [].}
Constructs an ANSI-256 palette color. Source   Edit  
proc initTerminalStyle(foreground = colorDefault; background = colorDefault;
                       attributes: set[TextAttribute] = {}): TerminalStyle {.
    ...raises: [], tags: [], forbids: [].}
Creates a reusable style. Default colors are left unchanged. Source   Edit  
proc italic(values`gensym41: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc magenta(values`gensym12: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc negative(values`gensym45: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc onIndexed(index: range[0 .. 255]; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies an ANSI-256 background color. Source   Edit  
proc onRgb(red, green, blue: range[0 .. 255]; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies a 24-bit RGB background color. Source   Edit  
proc overline(values`gensym50: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc red(values`gensym8: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc reverse(values`gensym46: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc rgb(red, green, blue: range[0 .. 255]; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Applies a 24-bit RGB foreground color. Source   Edit  
proc rgbColor(red, green, blue: range[0 .. 255]): TerminalColor {....raises: [],
    tags: [], forbids: [].}
Constructs a 24-bit true-color value. Source   Edit  
proc strikethrough(values`gensym49: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc style(value: string; textStyle: TerminalStyle; enabled = true): string {.
    ...raises: [], tags: [], forbids: [].}
Concise alias for applyStyle. Source   Edit  
proc style(values: varargs[string, `$`]; style: string): string {....raises: [],
    tags: [], forbids: [].}
Applies a raw SGR sequence. Prefer TerminalStyle for new code. Source   Edit  
proc styled(textStyle: TerminalStyle; values: varargs[string, `$`]): string {.
    ...raises: [], tags: [], forbids: [].}
Concatenates heterogeneous values and applies textStyle. Source   Edit  
proc underline(values`gensym42: varargs[string, $]): string {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc white(values`gensym14: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc yellow(values`gensym10: varargs[string, $]): string {....raises: [], tags: [],
    forbids: [].}
Source   Edit