chickadee » ansi-escape-sequences

ansi-escape-sequences

Description

Procedures to generate ANSI escape sequences.

Author

Mario Domenech Goulart

Requirements

None

Procedures

(cursor-position #!optional (line 0) (column 0)) procedure

Move the cursor to the specified position (coordinates). If a position is not specified, the cursor is moved to the home position at the upper-left corner of the screen (line 0, column 0).

(cursor-up lines) procedure

Move the cursor up by the specified number of lines without changing columns.

(cursor-down lines) procedure

Move the cursor down by the specified number of lines without changing columns.

(cursor-forward columns) procedure

Move the cursor forward by the specified number of columns without changing lines.

(cursor-backward columns) procedure

Move the cursor back by the specified number of columns without changing lines.

(save-cursor-position) procedure

Save the current cursor position. You can move the cursor to the saved cursor position by using the restore-cursor-position procedure.

(restore-cursor-position) procedure

Return the cursor to the position stored by the save-cursor-position.

(erase-display) procedure

Clear the screen and move the cursor to the home position (line 0, column 0).

(erase-line) procedure

Clear all characters from the cursor position to the end of the line (including the character at the cursor position).

(set-mode attrib) procedure

Change the screen width or type to the mode specified by one of the following values (symbols):

  • 40x25-monochrome
  • 40x25-color
  • 80x25-monochrome
  • 80x25-color
  • 320x200-4-color
  • 320x200-monochrome
  • 640x200-monochrome
  • line-wrapping
  • 320x200-color
  • 640x200-color
  • 640x350-monochrome
  • 640x350-color
  • 640x480-monochrome
  • 640x480-color
  • 320x200-color
(reset-mode attrib) procedure

Reset the mode by using the same values as set-mode.

(set-text attribs text #!optional (reset #t)) procedure

Change the colors and attributes of text (such as bold and underline) displayed on the screen. The following attributes are available (symbols):

  • reset
  • bold
  • underscore
  • blink
  • reverse-video
  • concealed
  • fg-black
  • fg-red
  • fg-green
  • fg-yellow
  • fg-blue
  • fg-magenta
  • fg-cyan
  • fg-white
  • bg-black
  • bg-red
  • bg-green
  • bg-yellow
  • bg-blue
  • bg-magenta
  • bg-cyan
  • bg-white

bg- is for background. fg- is for foreground.

Examples

There are videos showing the execution of the program below: OGV (Theora), AVI

(use posix ansi-escape-sequences)

(set-buffering-mode! (current-output-port) #:none)

(display (save-cursor-position))
(for-each (lambda (letter)
            (display letter)
            (sleep 1)
            (cursor-forward 1))
          '("c" "h" "i" "c" "k" "e" "n"))

(display " ")
(for-each (lambda (letter)
            (display (set-text '(bg-black fg-yellow) letter))
            (sleep 1)
            (cursor-forward 1))
          '("r" "o" "c" "k" "s" "!"))

(display (restore-cursor-position))
(display (erase-line))

(for-each (lambda (letter)
            (display letter)
            (sleep 1)
            (cursor-forward 1))
          '("c" "h" "i" "c" "k" "e" "n"))

(display " ")
(for-each (lambda (letter)
            (display (set-text '(bg-red fg-white) letter))
            (sleep 1)
            (cursor-forward 1))
          '("r" "u" "l" "e" "s" "!"))

(print "")

License

BSD

Version history

Version 0.2

Fixed escape sequences with more than one argument (reported by Felix)

Version 0.1

Initial release

Contents »