Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
- }
- }
Add Comment
Please, Sign In to add comment