Class: Binocs::TUI::AgentOutput

Inherits:
Window
  • Object
show all
Defined in:
lib/binocs/tui/agent_output.rb

Instance Attribute Summary collapse

Attributes inherited from Window

#height, #left, #top, #width, #win

Instance Method Summary collapse

Methods inherited from Window

#clear, #close, #copy_to_clipboard, #draw_box, #noutrefresh, #refresh, #resize, #write, #write_centered

Constructor Details

#initialize(height:, width:, top:, left:) ⇒ AgentOutput

Returns a new instance of AgentOutput.



8
9
10
11
12
13
14
15
# File 'lib/binocs/tui/agent_output.rb', line 8

def initialize(height:, width:, top:, left:)
  super
  @agent = nil
  @scroll_offset = 0
  @auto_scroll = true
  @output_lines = []
  @last_read_size = 0
end

Instance Attribute Details

#agentObject

Returns the value of attribute agent.



6
7
8
# File 'lib/binocs/tui/agent_output.rb', line 6

def agent
  @agent
end

#auto_scrollObject

Returns the value of attribute auto_scroll.



6
7
8
# File 'lib/binocs/tui/agent_output.rb', line 6

def auto_scroll
  @auto_scroll
end

#scroll_offsetObject

Returns the value of attribute scroll_offset.



6
7
8
# File 'lib/binocs/tui/agent_output.rb', line 6

def scroll_offset
  @scroll_offset
end

Instance Method Details

#drawObject



72
73
74
75
76
77
78
79
80
# File 'lib/binocs/tui/agent_output.rb', line 72

def draw
  return unless @agent

  clear
  draw_box(build_title)
  draw_output
  draw_status_bar
  refresh
end

#go_to_bottomObject



66
67
68
69
70
# File 'lib/binocs/tui/agent_output.rb', line 66

def go_to_bottom
  max_scroll = [@output_lines.length - content_height, 0].max
  @scroll_offset = max_scroll
  @auto_scroll = true
end

#go_to_topObject



61
62
63
64
# File 'lib/binocs/tui/agent_output.rb', line 61

def go_to_top
  @auto_scroll = false
  @scroll_offset = 0
end

#load_outputObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/binocs/tui/agent_output.rb', line 26

def load_output
  return unless @agent

  output = @agent.output
  @output_lines = output.split("\n")

  # Auto-scroll to bottom if enabled
  if @auto_scroll
    max_scroll = [@output_lines.length - content_height, 0].max
    @scroll_offset = max_scroll
  end
end

#page_downObject



55
56
57
58
59
# File 'lib/binocs/tui/agent_output.rb', line 55

def page_down
  max_scroll = [@output_lines.length - content_height, 0].max
  @scroll_offset = [@scroll_offset + content_height, max_scroll].min
  @auto_scroll = @scroll_offset == max_scroll
end

#page_upObject



50
51
52
53
# File 'lib/binocs/tui/agent_output.rb', line 50

def page_up
  @auto_scroll = false
  @scroll_offset = [@scroll_offset - content_height, 0].max
end

#scroll_downObject



44
45
46
47
48
# File 'lib/binocs/tui/agent_output.rb', line 44

def scroll_down
  max_scroll = [@output_lines.length - content_height, 0].max
  @scroll_offset = [@scroll_offset + 1, max_scroll].min
  @auto_scroll = @scroll_offset == max_scroll
end

#scroll_upObject



39
40
41
42
# File 'lib/binocs/tui/agent_output.rb', line 39

def scroll_up
  @auto_scroll = false
  @scroll_offset = [@scroll_offset - 1, 0].max
end

#set_agent(agent) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/binocs/tui/agent_output.rb', line 17

def set_agent(agent)
  @agent = agent
  @scroll_offset = 0
  @auto_scroll = true
  @output_lines = []
  @last_read_size = 0
  load_output
end