[ Tcllib Home | Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

term::ansi::code::ctrl(n) 0.3 tcllib "Terminal control"


term::ansi::code::ctrl - ANSI control sequences

Table Of Contents


  • package require Tcl 8.4
  • package require term::ansi::code ?0.2?
  • package require term::ansi::code::ctrl ?0.3?


This package provides symbolic names for the ANSI control sequences. For each sequence a single command is provided which returns the sequence as its result. None of the commands of this package write to a channel; that is handled by higher level packages, like term::ansi::send.




This command is for introspection. It returns as its result a list containing the names of all attribute commands.

::term::ansi::code::ctrl::import ?ns? ?arg...?

This command imports some or all attribute commands into the namespace ns. This is by default the namespace ctrl. Note that this is relative namespace name, placing the imported command into a child of the current namespace. By default all commands are imported, this can howver be restricted by listing the names of the wanted commands after the namespace argument.



Erase (to) End Of Line


Erase (to) Start Of Line


Erase (current) Line


Erase Down (to bottom)


Erase Up (to top)


Erase Screen


Scroll Down


Scroll Up


Cursor Home


Save Cursor


Restore Cursor (Unsave)


Save Cursor + Attributes


Restore Cursor + Attributes


Set Tab (@ current position)


Clear Tab (@ current position)


Clear All Tabs


Query Device Code


Query Device Status


Query Cursor Position


Reset Device


Enable Line Wrap


Disable Line Wrap


Enter Graphics Mode


Exit Graphics Mode

::term::ansi::code::ctrl::scs0 tag

Set default character set

::term::ansi::code::ctrl::scs1 tag

Set alternate character set Select Character Set.

Choose which character set is used for either default (scs0) or alternate font (scs1). This does not change whether default or alternate font are used, only their definition.

The legal tags, and their meanings, are:


United Kingdom Set




Special Graphics


Alternate Character ROM Standard Character Set


Alternate Character ROM Special Graphics

::term::ansi::code::ctrl::sda arg...

Set Display Attributes. The arguments are the code sequences for the possible attributes, as provided by the package term::ansi::code::attr. For convenience this package also provides additional commands each setting a single specific attribute.


Set text color to Black.


Set text color to Red.


Set text color to Green.


Set text color to Yellow.


Set text color to Blue.


Set text color to Magenta.


Set text color to Cyan.


Set text color to White.


Set default text color (Black).


Set background to Black.


Set background to Red.


Set background to Green.


Set background to Yellow.


Set background to Blue.


Set background to Magenta.


Set background to Cyan.


Set background to White.


Set default background (Transparent).


Bold on.


Dim on.


Italics on.


Underscore on.


Blink on.


Reverse on.


Hidden on.


Strike-through on.


Bold off.


Italics off.


Underscore off.


Blink off.


Reverse off.


Hidden off.


Strike-through off.


Reset all attributes to their default values.

::term::ansi::send::fcp row col

Force Cursor Position (aka Go To).

::term::ansi::code::ctrl::cu ?n?

Cursor Up. n defaults to 1.

::term::ansi::code::ctrl::cd ?n?

Cursor Down. n defaults to 1.

::term::ansi::code::ctrl::cf ?n?

Cursor Forward. n defaults to 1.

::term::ansi::code::ctrl::cb ?n?

Cursor Backward. n defaults to 1.

::term::ansi::code::ctrl::ss ?s e?

Scroll Screen (entire display, or between rows start end, inclusive).

::term::ansi::code::ctrl::skd code str

Set Key Definition.

::term::ansi::code::ctrl::title str

Set the terminal title.


Switch to character/box graphics. I.e. switch to the alternate font.


Switch to regular characters. I.e. switch to the default font.


Character graphics, Top Left Corner.


Character graphics, Top Right Corner.


Character graphics, Bottom Right Corner.


Character graphics, Bottom Left Corner.


Character graphics, Left T Junction.


Character graphics, Top T Junction.


Character graphics, Right T Junction.


Character graphics, Bottom T Junction.


Character graphics, Four-Way Junction.


Character graphics, Horizontal Line.


Character graphics, Vertical Line.

::term::ansi::code::ctrl::groptim str

Optimize character graphics. The generator commands above create way to many superfluous commands shifting into and out of the graphics mode. This command removes all shifts which are not needed. To this end it also knows which characters will look the same in both modes, to handle strings created outside of this package.


Clear screen. In essence a sequence of CursorHome + EraseDown.


Initialize default and alternate fonts to ASCII and box graphics.

::term::ansi::code::ctrl::showat row col text

Format the block of text for display at the specified location.

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category term of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.


ansi, attribute control, color control, control, terminal


Terminal control