This module contains a few procedures to control the
terminal (also called
console). On UNIX, the implementation simply uses ANSI escape sequences and does not depend on any other module, on Windows it uses the Windows API. Changing the style is permanent even after program termination! Use the code
system.addQuitProc(resetAttributes) to restore the defaults.
TStyle = enum
styleBright = 1,
styleDim,
styleUnknown,
styleUnderscore = 4,
styleBlink,
styleReverse = 7,
styleHidden
-
different styles for text output
TForegroundColor = enum
fgBlack = 30,
fgRed,
fgGreen,
fgYellow,
fgBlue,
fgMagenta,
fgCyan,
fgWhite
-
terminal's foreground colors
TBackgroundColor = enum
bgBlack = 40,
bgRed,
bgGreen,
bgYellow,
bgBlue,
bgMagenta,
bgCyan,
bgWhite
-
terminal's background colors
proc setCursorPos(x, y: int) {.raises: [EIO], tags: [FWriteIO].}
-
sets the terminal's cursor to the (x,y) position. (0,0) is the upper left of the screen.
proc setCursorXPos(x: int) {.raises: [EIO], tags: [FWriteIO].}
-
sets the terminal's cursor to the x position. The y position is not changed.
proc cursorUp(count = 1) {.raises: [EIO], tags: [FWriteIO].}
-
Moves the cursor up by count rows.
proc cursorDown(count = 1) {.raises: [EIO], tags: [FWriteIO].}
-
Moves the cursor down by count rows.
proc cursorForward(count = 1) {.raises: [EIO], tags: [FWriteIO].}
-
Moves the cursor forward by count columns.
proc cursorBackward(count = 1) {.raises: [EIO], tags: [FWriteIO].}
-
Moves the cursor backward by count columns.
proc eraseLine() {.raises: [EIO], tags: [FWriteIO].}
-
Erases the entire current line.
proc eraseScreen() {.raises: [EIO], tags: [FWriteIO].}
-
Erases the screen with the background colour and moves the cursor to home.
proc resetAttributes() {.noconv, raises: [EIO], tags: [FWriteIO].}
-
resets all attributes; it is advisable to register this as a quit proc with system.addQuitProc(resetAttributes).
proc setStyle(style: set[TStyle]) {.raises: [EIO], tags: [FWriteIO].}
-
sets the terminal style
proc writeStyled(txt: string; style: set[TStyle] = {styleBright}) {.
raises: [EIO], tags: [FWriteIO].}
-
writes the text txt in a given style.
proc setForegroundColor(fg: TForegroundColor; bright = false) {.raises: [EIO],
tags: [FWriteIO].}
-
sets the terminal's foreground color
proc setBackgroundColor(bg: TBackgroundColor; bright = false) {.raises: [EIO],
tags: [FWriteIO].}
-
sets the terminal's background color
proc isatty(f: TFile): bool {.raises: [], tags: [].}
-
returns true if f is associated with a terminal device.
macro styledEcho(m: varargs[expr]): stmt
-
to be documented.