Module terminal

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.

Types

Style = enum 
  styleBright = 1,            ## bright text
  styleDim,                   ## dim text
  styleUnknown,               ## unknown
  styleUnderscore = 4,        ## underscored text
  styleBlink,                 ## blinking/bold text
  styleReverse = 7,           ## unknown
  styleHidden                 ## hidden text
different styles for text output   Source
ForegroundColor = enum 
  fgBlack = 30,               ## black
  fgRed,                      ## red
  fgGreen,                    ## green
  fgYellow,                   ## yellow
  fgBlue,                     ## blue
  fgMagenta,                  ## magenta
  fgCyan,                     ## cyan
  fgWhite                     ## white
terminal's foreground colors   Source
BackgroundColor = enum 
  bgBlack = 40,               ## black
  bgRed,                      ## red
  bgGreen,                    ## green
  bgYellow,                   ## yellow
  bgBlue,                     ## blue
  bgMagenta,                  ## magenta
  bgCyan,                     ## cyan
  bgWhite                     ## white
terminal's background colors   Source

Procs

proc setCursorPos(x, y: int) {.raises: [IOError], tags: [WriteIOEffect].}
sets the terminal's cursor to the (x,y) position. (0,0) is the upper left of the screen.   Source
proc setCursorXPos(x: int) {.raises: [IOError], tags: [WriteIOEffect].}
sets the terminal's cursor to the x position. The y position is not changed.   Source
proc cursorUp(count = 1) {.raises: [IOError], tags: [WriteIOEffect].}
Moves the cursor up by count rows.   Source
proc cursorDown(count = 1) {.raises: [IOError], tags: [WriteIOEffect].}
Moves the cursor down by count rows.   Source
proc cursorForward(count = 1) {.raises: [IOError], tags: [WriteIOEffect].}
Moves the cursor forward by count columns.   Source
proc cursorBackward(count = 1) {.raises: [IOError], tags: [WriteIOEffect].}
Moves the cursor backward by count columns.   Source
proc eraseLine() {.raises: [IOError], tags: [WriteIOEffect].}
Erases the entire current line.   Source
proc eraseScreen() {.raises: [IOError], tags: [WriteIOEffect].}
Erases the screen with the background colour and moves the cursor to home.   Source
proc resetAttributes() {.noconv, raises: [IOError], tags: [WriteIOEffect].}
resets all attributes; it is advisable to register this as a quit proc with system.addQuitProc(resetAttributes).   Source
proc setStyle(style: set[Style]) {.raises: [IOError], tags: [WriteIOEffect].}
sets the terminal style   Source
proc writeStyled(txt: string; style: set[Style] = {styleBright}) {.
    raises: [IOError], tags: [WriteIOEffect].}
writes the text txt in a given style.   Source
proc setForegroundColor(fg: ForegroundColor; bright = false) {.
    raises: [IOError], tags: [WriteIOEffect].}
sets the terminal's foreground color   Source
proc setBackgroundColor(bg: BackgroundColor; bright = false) {.
    raises: [IOError], tags: [WriteIOEffect].}
sets the terminal's background color   Source
proc isatty(f: File): bool {.raises: [], tags: [].}
returns true if f is associated with a terminal device.   Source
proc getch(): char {.raises: [], tags: [].}
Read a single character from the terminal, blocking until it is entered. The character is not printed to the terminal. This is not available for Windows.   Source

Macros

macro styledEcho(m: varargs[expr]): stmt
to be documented.   Source