Guest User

Untitled

a guest
May 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import os/Terminal
  2. import math
  3.  
  4. ProgressBar: class {
  5. value: UInt = 0
  6. maxval: UInt = 100
  7. barwidth: UInt = 80
  8.  
  9. text := "Please wait..."
  10.  
  11. thorpe := "#" /* I wanted this to be a Char, but Chars don't have times() */
  12. period := "."
  13.  
  14. thorpecolor := Color blue
  15. periodcolor := Color grey
  16.  
  17. init: func() {
  18. println()
  19. }
  20.  
  21. init: func ~withtext (=text) {
  22. println()
  23. }
  24.  
  25. update: func() {
  26. "\e[A" print() /* Go up one line */
  27. "\b" times(999) print() /* Erase that line and go to the start of the line */
  28.  
  29. this text println() /* Print the status text */
  30.  
  31. ratio := (barwidth as Float/maxval as Float)
  32.  
  33. Terminal setFgColor(this thorpecolor)
  34. this thorpe times(floor(value * ratio)) print()
  35.  
  36. Terminal setFgColor(this periodcolor)
  37. this period times(barwidth - floor(value * ratio)) print()
  38.  
  39. Terminal reset()
  40. }
  41.  
  42. update: func ~withVal (val: Int) {
  43. if (val > maxval) {
  44. update(maxval)
  45. } else if (val < 0) {
  46. update(0)
  47. } else {
  48. this value = val
  49. update()
  50. }
  51. }
  52.  
  53. finish: func() {
  54. this update(maxval)
  55. Terminal reset()
  56. "\n" print()
  57. }
  58. }
Add Comment
Please, Sign In to add comment