Class: Tryouts::CLI::LiveStatusManager

Inherits:
Object
  • Object
show all
Defined in:
lib/tryouts/cli/formatters/live_status_manager.rb

Overview

Centralized manager for live status display across all formatters Replaces the decorator pattern with inhouse integration

Instance Method Summary collapse

Constructor Details

#initialize(formatter, options = {}) ⇒ LiveStatusManager

Returns a new instance of LiveStatusManager.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 11

def initialize(formatter, options = {})
  @formatter  = formatter
  @enabled    = should_enable_live_status?(formatter, options)
  @show_debug = options.fetch(:debug, false)

  return unless @enabled

  # Initialize state tracking and display
  @state           = TestRunState.empty
  @display         = TTYStatusDisplay.new(@formatter.stdout, options)
  @status_reserved = false

  debug_log('LiveStatusManager: Enabled with inhouse integration')
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 26

def enabled?
  @enabled
end

#handle_event(event_type, *args) ⇒ Object

Main event handling - called by OutputManager for each formatter event



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 52

def handle_event(event_type, *args, **)
  return unless @enabled

  # Update state based on the event
  @state = @state.update_from_event(event_type, *args, **)

  # Handle special events that need display coordination
  case event_type
  when :phase_header
    message, file_count, level = args
    if level == 0 && message.include?('PROCESSING') && file_count
      reserve_status_area
    end
  when :file_start, :file_end, :test_result
    update_display
  when :batch_summary
    # Clear status area before showing batch summary to avoid interference
    clear_status_area
  when :grand_total
    # Ensure status area is cleared (redundant safety check)
    clear_status_area if @status_reserved
  end
end

#should_enable_live_status?(formatter, options) ⇒ Boolean

Check if formatter and environment support live status

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 31

def should_enable_live_status?(formatter, options)
  # Must be explicitly requested
  return false unless options[:live_status] || options[:live]

  # Check formatter capabilities
  capabilities = formatter.live_status_capabilities
  return false unless capabilities[:supports_coordination]

  # Check TTY availability
  require_relative '../tty_detector'
  tty_check = TTYDetector.check_tty_support(debug: options[:debug])

  unless tty_check[:available]
    debug_log("Live status disabled: #{tty_check[:reason]}")
    return false
  end

  true
end

#update_status(state_updates = {}) ⇒ Object

Allow formatter to directly update live status (optional integration point)



77
78
79
80
81
82
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 77

def update_status(state_updates = {})
  return unless @enabled

  @state = @state.with(**state_updates) unless state_updates.empty?
  update_display
end

#write_outputObject

Output coordination methods



85
86
87
88
89
90
91
92
93
94
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 85

def write_output
  return yield unless @enabled

  # If status area is reserved, coordinate the output
  if @status_reserved
    @display.write_scrolling(yield)
  else
    yield
  end
end

#write_string(text) ⇒ Object



96
97
98
99
100
101
102
103
104
# File 'lib/tryouts/cli/formatters/live_status_manager.rb', line 96

def write_string(text)
  return @formatter.stdout.print(text) unless @enabled

  if @status_reserved
    @display.write_scrolling(text)
  else
    @formatter.stdout.print(text)
  end
end