Skip to content

Instantly share code, notes, and snippets.

@cdwilson
Created June 22, 2011 21:41
Show Gist options
  • Save cdwilson/1041291 to your computer and use it in GitHub Desktop.
Save cdwilson/1041291 to your computer and use it in GitHub Desktop.
progress bar in expect
#!/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