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

TStyle = 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
TForegroundColor = enum 
  fgBlack = 30,               ## black
  fgRed,                      ## red
  fgGreen,                    ## green
  fgYellow,                   ## yellow
  fgBlue,                     ## blue
  fgMagenta,                  ## magenta
  fgCyan,                     ## cyan
  fgWhite                     ## white
terminal's foreground colors
TBackgroundColor = enum 
  bgBlack = 40,               ## black
  bgRed,                      ## red
  bgGreen,                    ## green
  bgYellow,                   ## yellow
  bgBlue,                     ## blue
  bgMagenta,                  ## magenta
  bgCyan,                     ## cyan
  bgWhite                     ## white
terminal's background colors

Procs

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.

Macros

macro styledEcho(m: varargs[expr]): stmt
to be documented.
Generated: 2014-03-11 21:26:42 UTC