Class: RSpecTelemetry::Trace::Viewer::TimeBar

Inherits:
Object
  • Object
show all
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

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)

  draw_bar(canvas, rect, current, TuiTui::DisplayText.new(label).width)
  canvas
end