summaryrefslogtreecommitdiffstats
path: root/tcllib/support/devel/sak/util/anim.tcl
blob: 302ff04c5e76d5f03d322a98862031bf19389b96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# -*- tcl -*-
# (C) 2006-2013 Andreas Kupries <andreas_kupries@users.sourceforge.net>
##
# ###

namespace eval ::sak::animate {
    # EL (Erase Line)
    #    Sequence: ESC [ n K
    # ** Effect: if n is 0 or missing, clear from cursor to end of line
    #    Effect: if n is 1, clear from beginning of line to cursor
    #    Effect: if n is 2, clear entire line

    variable eeol \033\[K
}

# ###

proc ::sak::animate::init {} {
    variable prefix
    variable n      0
    variable max    [llength $prefix]
}

proc ::sak::animate::next {string} {
    variable prefix
    variable n
    variable max
    variable eeol

    puts -nonewline stdout \r\[[lindex $prefix $n]\]\ $string$eeol
    flush           stdout

    incr n ; if {$n >= $max} {set n 0}
    return
}

proc ::sak::animate::last {string} {
    variable clear

    puts  stdout \r\[$clear\]\ $string
    flush stdout
    return
}

# ###

namespace eval ::sak::animate {
    namespace export init next last

    variable  prefix {
	{*   }	{*   }	{*   }	{*   }	{*   }
	{ *  }	{ *  }	{ *  }	{ *  }	{ *  }
	{  * }	{  * }	{  * }	{  * }	{  * }
	{   *}	{   *}	{   *}	{   *}	{   *}
	{  * }	{  * }	{  * }	{  * }	{  * }
	{ *  }	{ *  }	{ *  }	{ *  }	{ *  }
    }
    variable clear {    }
}

##
# ###

package provide sak::animate 1.0