Class: RSpecTelemetry::Trace::Viewer::FollowController
- Inherits:
-
Object
- Object
- RSpecTelemetry::Trace::Viewer::FollowController
- Defined in:
- lib/rspec_telemetry/trace/viewer/follow_controller.rb
Overview
Owns “follow mode”: draining a live source into the Document, keeping the cursor parked at the tail, and advancing the pending spinner.
Constant Summary collapse
- SPINNER =
%w[| / - \\].freeze
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#drain(document) ⇒ Object
Advance the spinner and fold any new source lines into the document.
-
#initialize(source:, active:) ⇒ FollowController
constructor
A new instance of FollowController.
-
#reset_stick(at_end:) ⇒ Object
Re-evaluate sticking after the cursor moves (e.g. App#go_to).
- #spinner ⇒ Object
-
#stick(list) ⇒ Object
Keep the cursor parked at the tail while sticking.
-
#toggle(at_end:) ⇒ Object
Flip follow on/off; resume tail-sticking only when parked at the end.
- #wants_tick? ⇒ Boolean
Constructor Details
#initialize(source:, active:) ⇒ FollowController
Returns a new instance of FollowController.
11 12 13 14 15 16 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 11 def initialize(source:, active:) @source = source @active = active @stick = active @spin = 0 end |
Instance Method Details
#active? ⇒ Boolean
18 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 18 def active? = @active |
#drain(document) ⇒ Object
Advance the spinner and fold any new source lines into the document.
35 36 37 38 39 40 41 42 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 35 def drain(document) return false unless @active @spin += 1 lines = @source ? @source.drain : [] lines.each { |line| document.apply(line) } !lines.empty? end |
#reset_stick(at_end:) ⇒ Object
Re-evaluate sticking after the cursor moves (e.g. App#go_to).
30 31 32 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 30 def reset_stick(at_end:) @stick = @active && at_end end |
#spinner ⇒ Object
20 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 20 def spinner = SPINNER[@spin % SPINNER.length] |
#stick(list) ⇒ Object
Keep the cursor parked at the tail while sticking.
45 46 47 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 45 def stick(list) list.to_end if @stick end |
#toggle(at_end:) ⇒ Object
Flip follow on/off; resume tail-sticking only when parked at the end.
23 24 25 26 27 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 23 def toggle(at_end:) @active = !@active @stick = @active && at_end @active end |
#wants_tick? ⇒ Boolean
19 |
# File 'lib/rspec_telemetry/trace/viewer/follow_controller.rb', line 19 def wants_tick? = @active |