Class: RSpecTelemetry::Trace::Viewer::TimeBar
- Inherits:
-
Object
- Object
- RSpecTelemetry::Trace::Viewer::TimeBar
- Defined in:
- lib/rspec_telemetry/trace/viewer/time_bar.rb
Constant Summary collapse
- LABEL =
TuiTui::Style.new(attrs: [:bold])
- FILL =
TuiTui::Style.new(fg: :green)
- TRACK =
TuiTui::Style.new(attrs: [:dim])
Instance Method Summary collapse
- #draw(canvas, rect) ⇒ Object
-
#initialize(current_ms:, total_ms:) ⇒ TimeBar
constructor
A new instance of TimeBar.
Constructor Details
#initialize(current_ms:, total_ms:) ⇒ TimeBar
Returns a new instance of TimeBar.
14 15 16 17 |
# File 'lib/rspec_telemetry/trace/viewer/time_bar.rb', line 14 def initialize(current_ms:, total_ms:) @current = current_ms @total = total_ms end |
Instance Method Details
#draw(canvas, rect) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rspec_telemetry/trace/viewer/time_bar.rb', line 19 def draw(canvas, rect) canvas.fill(rect, TRACK) return canvas unless @total && @total.positive? current = (@current || 0).clamp(0, @total) percent = (current.to_f / @total * 100).round label = " #{Format.ms(current)} / #{Format.ms(@total)} #{percent}% " canvas.text(rect.row, rect.col, label, LABEL) (canvas, rect, current, TuiTui::DisplayText.new(label).width) canvas end |