This piece of code makes displaying coloured text (and much more) easy for TCL programmer. It's a package written in pure-TCL.
Full manual page is placed here: http://sqlitestudio.one.pl/libterm/libterm.html
Short description of procedures provided by the package:
The library sources are placed here: http://sqlitestudio.one.pl/libterm/libterm-0.9.tar.gz
Version 0.9 could be lilbit unstable (sometimes 'scroll' command doesn't work as it should).
If anybody has idea how to speed-up 'tputs' command, fix 'scroll' command, or simply add some another one, their concepts are welcome :)
Well, here are few examples of how can it be used:
#!/bin/sh #\ exec tclsh $0 ${@} package require libterm namespace import ::libterm::* rtputs "%BHello %Rworld%Y!"
It will simply display "Hello world!", but the first word will be blue, the second one will be red and the interjection will be yellow.
#!/bin/sh #\ exec tclsh $0 ${@} package require libterm namespace import ::libterm::* erase screen both set interval 100 set txt "Sample text" foreach {col1 col2} {b B r R g G y Y m M w W} { for {set i 0} {$i < 5} {incr i} { mv 5,10 rtputs "%${col1}$txt" after $interval {set sleep 1} vwait sleep mv 5,10 rtputs "%${col2}$txt" after $interval {set sleep 1} vwait sleep } }
This code will display text "Sample text" in the 10th column of the 5th raw of console screen. The text will change its colors for each 100 miliseconds, which will give 'blinking' text effect.
#!/bin/sh #\ exec tclsh $0 ${@} package require libterm namespace import ::libterm::* erase screen both proc pad {str char cnt} { if {$cnt > [string length $str]} { for {set i [string length $str]} {$i < $cnt} {incr i} { append str $char } } return $str } for {set i 0} {$i <= 100} {incr i} { mv 3,20 set progress [expr {$i/5}] set left [expr {20-$progress}] rtputs "%b\[%G[pad [pad {} {=} $progress]> { } 21]%b\]" mv 4,29 tputs "%#r%Y<$i%%>" after 100 {set sleep 1} vwait sleep }
This is simple 'progress bar' example made with libterm package.
VI 2004-05-29 Minimalist Curses is somewhat related