Class: Nitrous::ProgressBar
- Inherits:
-
Object
- Object
- Nitrous::ProgressBar
- Defined in:
- lib/nitrous/progress_bar.rb
Constant Summary collapse
- RED =
101
- GREEN =
102
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #delete_bar ⇒ Object
- #draw ⇒ Object
- #draw_bar(color, width) ⇒ Object
-
#initialize(steps) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #redraw_bar ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize(steps) ⇒ ProgressBar
Returns a new instance of ProgressBar.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nitrous/progress_bar.rb', line 44 def initialize(steps) @total_steps = steps @step = 0 @color = GREEN Curses.init_screen @dimensions = [Curses.stdscr.maxx, Curses.stdscr.maxy] Curses.close_screen $stdout.puts "" $stdout = ProgressBarAwareStandardOut.new($stdout, self) @text = "" end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
42 43 44 |
# File 'lib/nitrous/progress_bar.rb', line 42 def color @color end |
#text ⇒ Object
Returns the value of attribute text.
42 43 44 |
# File 'lib/nitrous/progress_bar.rb', line 42 def text @text end |
Instance Method Details
#delete_bar ⇒ Object
68 69 70 |
# File 'lib/nitrous/progress_bar.rb', line 68 def $stdout.direct_write("\e[1F\e[0K") end |
#draw ⇒ Object
72 73 74 75 |
# File 'lib/nitrous/progress_bar.rb', line 72 def draw end |
#draw_bar(color, width) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/nitrous/progress_bar.rb', line 61 def (color, width) content = @text[0..[width, @text.length].min] + " " * [width - @text.length, 0].max $stdout.direct_write("\e[#{color}m#{content}\e[0m") $stdout.direct_write(@text[(width + 1)..-1]) if @text.length > width $stdout.direct_write("\n") end |
#redraw_bar ⇒ Object
77 78 79 80 |
# File 'lib/nitrous/progress_bar.rb', line 77 def (@color, (@dimensions[0].to_f/@total_steps)*@step) STDOUT.flush end |
#step ⇒ Object
56 57 58 59 |
# File 'lib/nitrous/progress_bar.rb', line 56 def step @step += 1 draw end |