You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.2 KiB
55 lines
1.2 KiB
2 years ago
|
|
||
|
if {$::argc == 1} {
|
||
|
set persec $::argv
|
||
|
} else {
|
||
|
set persec 1
|
||
|
}
|
||
|
if {$persec > 1000} {
|
||
|
puts stderr "WARNING: (>1000) sub millisecond scheduling not available - will go full speed"
|
||
|
flush stderr
|
||
|
after 500
|
||
|
}
|
||
|
#--- confg ---
|
||
|
set newline_every_x_seconds 5
|
||
|
#---
|
||
|
chan configure stdout -blocking 1 -buffering none
|
||
|
set counter 0
|
||
|
set ms [expr {1000 / $persec}]
|
||
|
set nl_every [expr {$persec * $newline_every_x_seconds}]
|
||
|
|
||
|
proc schedule {} {
|
||
|
after idle [list after 0 ::emit]
|
||
|
tailcall after $::ms ::schedule
|
||
|
}
|
||
|
|
||
|
proc emit {} {
|
||
|
upvar ::counter c
|
||
|
puts -nonewline "\x1b\[1000D$c"
|
||
|
|
||
|
#if {($c > 1) && (($c % $::nl_every) == 0)} {
|
||
|
# puts stdout $c
|
||
|
# flush stdout
|
||
|
#} else {
|
||
|
# puts -nonewline "\x1b\[1000D$c"
|
||
|
#}
|
||
|
#flush stdout
|
||
|
incr c
|
||
|
}
|
||
|
chan configure stdin -blocking 0 -buffering none
|
||
|
chan event stdin readable [list apply {{chan} {
|
||
|
set chunk [chan read $chan]
|
||
|
if {[string length $chunk]} {
|
||
|
if {[string match "q*" [string tolower $chunk]]} {
|
||
|
set ::forever 0
|
||
|
}
|
||
|
}
|
||
|
if {[chan eof $chan]} {
|
||
|
chan event $chan readable {}
|
||
|
}
|
||
|
}} stdin]
|
||
|
|
||
|
schedule
|
||
|
vwait ::forever
|
||
|
|
||
|
puts "-done-"
|