Created
June 22, 2011 21:41
-
-
Save cdwilson/1041291 to your computer and use it in GitHub Desktop.
progress bar in expect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
set total 10 | |
proc progress {cur tot} { | |
# if you don't want to redraw all the time, uncomment and change ferquency | |
#if {$cur % ($tot/300)} { return } | |
# set to total width of progress bar | |
set total 74 | |
set half [expr {$total/2}] | |
set percent [expr {100.*$cur/$tot}] | |
set val (\ [format "%6.2f%%" $percent]\ ) | |
set str "\r|[string repeat = [expr {round($percent*$total/100)}]][string repeat { } [expr {$total-round($percent*$total/100)}]]|" | |
set str "[string range $str 0 $half][string range $str [expr {$half+[string length $val]-1}] end] $val" | |
puts -nonewline stderr $str | |
} | |
for {set i 0} {$i <= $total} {incr i 1} { | |
progress $i $total | |
after 300 | |
} | |
puts "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment