Version 6 of ANSI

Updated 2014-05-06 18:25:08 by AMG

American National Standards Institute see: http://www.ansi.org/ . Does standardization of all sorts of things.

One example that many programmers will have encountered is the ASCII character set, which was a huge improvement over the vast number of different manufacturer encodings in use beforehand (of which only IBM's EBCDIC has survived in any meaningful way).

Also significant because, "ANSI escape codes are used to control text formatting and other output options on text terminals" [L1 ]. Terminal emulators for Linux have support for ANSI escape codes built in.

AM (6 may 2014) The other day someone asked about controlling the output on screen, so that the last line would be rewritten with new results. Here is a simple solution which works with these ANSI escape codes. Unfortunately you only get the proper effect on Linux terminals and other ANSI-enabled terminals. The code is, however, dead simple:

  • Move the cursor to the right position (\escape[10;0f)
  • Clear everything at this position and below (\escape[J)
  • Write the new output
# showcomp.tcl --
#     Small program to illustrate the use of ANSI sequences
#

while {1} {
    puts -nonewline "\x1b\[10;1f\x1b\[J"
    puts "Result: [clock seconds] - [expr {rand()}]"
    puts "Computing ..."
    after 1000
}

AMG: For single-line displays, e.g. progress meters, I use \r which rewinds to the start of the line. Then \x1b[K clears to end of line.

while {1} {
    puts -nonewline "\r[clock format [clock seconds]]\x1b\[K"
    flush stdout
    after 900
}