Version 2 of ASCII animation

Updated 2005-08-05 16:05:47 by suchenwi

Richard Suchenwirth 2005-08-05 - When a longer-running process runs in a terminal window, it may be helpful for the user to indicate that it is still active. Here's a simple way of producing some animation on stdout: You store the "phases" you want to display in a variable, and in certain intervals call ascii_animate which will display the first of the phases on stdout, followed by CR but no LF, so the next operation will occur in the same place. Also, the phases list is cycled, with the first element being moved to the end of the list. The example shows a short bar that seems to rotate :)


 set phases {- / | \\}

 proc ascii_animate _var {
    upvar 1 $_var var
    puts -nonewline [lindex $var 0]\r
    flush stdout
    set var [concat [lrange $var 1 end] [lindex $var 0]]
 }

#-- Test:

 while 1 {
    ascii_animate phases
    after 500
 }

Category Animation | Arts and crafts of Tcl-Tk programming