Created
May 29, 2010 14:41
-
-
Save wandernauta/418309 to your computer and use it in GitHub Desktop.
This file contains 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
import os/Terminal | |
import math | |
ProgressBar: class { | |
value: UInt = 0 | |
maxval: UInt = 100 | |
barwidth: UInt = 80 | |
text := "Please wait..." | |
thorpe := "#" /* I wanted this to be a Char, but Chars don't have times() */ | |
period := "." | |
thorpecolor := Color blue | |
periodcolor := Color grey | |
init: func() { | |
println() | |
} | |
init: func ~withtext (=text) { | |
println() | |
} | |
update: func() { | |
"\e[A" print() /* Go up one line */ | |
"\b" times(999) print() /* Erase that line and go to the start of the line */ | |
this text println() /* Print the status text */ | |
ratio := (barwidth as Float/maxval as Float) | |
Terminal setFgColor(this thorpecolor) | |
this thorpe times(floor(value * ratio)) print() | |
Terminal setFgColor(this periodcolor) | |
this period times(barwidth - floor(value * ratio)) print() | |
Terminal reset() | |
} | |
update: func ~withVal (val: Int) { | |
if (val > maxval) { | |
update(maxval) | |
} else if (val < 0) { | |
update(0) | |
} else { | |
this value = val | |
update() | |
} | |
} | |
finish: func() { | |
this update(maxval) | |
Terminal reset() | |
"\n" print() | |
} | |
} |
This file contains 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
import os/Time | |
import progress | |
import os/Terminal | |
pb := ProgressBar new("Reticulating splines...") | |
for (i in 0..10) { | |
pb update(i*10) | |
Time sleepMilli(200) | |
} | |
pb finish() | |
pb2 := ProgressBar new("Twiddling thumbs...") | |
pb2 thorpecolor = Color red | |
pb2 maxval = 200 | |
for (i in 0..200) { | |
if ((i % 10) == 0) pb2 text = "Twiddling %d thumbs..." format(i) | |
pb2 update(i) | |
Time sleepMilli(20) | |
} | |
pb2 finish() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment