Class: Audition::Progress::Line
- Defined in:
- lib/audition/progress.rb
Overview
One status line, rewritten in place for the whole scan and erased when it ends.
Constant Summary collapse
- REDRAW_INTERVAL =
Redraws closer together than this are invisible and cost a syscall on every file.
0.1- SPINNER =
Stands in for the counter while a stage runs work that cannot be counted, so the line still moves.
%w[| / - \\].freeze
- DEFAULT_WIDTH =
80- MIN_WIDTH =
24
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(io, style: nil, interval: REDRAW_INTERVAL) ⇒ Line
constructor
A new instance of Line.
- #update(progress) ⇒ Object
Methods inherited from Renderer
Constructor Details
#initialize(io, style: nil, interval: REDRAW_INTERVAL) ⇒ Line
Returns a new instance of Line.
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/audition/progress.rb', line 104 def initialize(io, style: nil, interval: REDRAW_INTERVAL) super(io, style: style) @interval = interval @width = self.class.width @drawn = 0 @heading = nil @redrawn_at = 0.0 @spin = 0 @mutex = Mutex.new @heartbeat = nil end |
Class Method Details
.width ⇒ Object
97 98 99 100 |
# File 'lib/audition/progress.rb', line 97 def self.width columns = ENV["COLUMNS"].to_i (columns >= MIN_WIDTH) ? columns : DEFAULT_WIDTH end |
Instance Method Details
#clear ⇒ Object
125 126 127 128 |
# File 'lib/audition/progress.rb', line 125 def clear stop_heartbeat @mutex.synchronize { erase } end |
#update(progress) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/audition/progress.rb', line 116 def update(progress) if progress.countable? stop_heartbeat else start_heartbeat(progress) end draw(progress) end |