Class: Binocs::TUI::AgentsList

Inherits:
Window
  • Object
show all
Defined in:
lib/binocs/tui/agents_list.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:) ⇒ AgentsList

Returns a new instance of AgentsList.



8
9
10
11
12
# File 'lib/binocs/tui/agents_list.rb', line 8

def initialize(height:, width:, top:, left:)
  super
  @selected_index = 0
  @scroll_offset = 0
end

Instance Attribute Details

#scroll_offsetObject

Returns the value of attribute scroll_offset.



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

def scroll_offset
  @scroll_offset
end

#selected_indexObject

Returns the value of attribute selected_index.



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

def selected_index
  @selected_index
end

Instance Method Details

#agentsObject



14
15
16
# File 'lib/binocs/tui/agents_list.rb', line 14

def agents
  @agents ||= []
end

#drawObject



53
54
55
56
57
58
59
60
# File 'lib/binocs/tui/agents_list.rb', line 53

def draw
  clear
  draw_box("Agents (#{agents.length} total, #{Binocs::Agent.running_count} running)")
  draw_header
  draw_agents
  draw_status_bar
  refresh
end

#go_to_bottomObject



48
49
50
51
# File 'lib/binocs/tui/agents_list.rb', line 48

def go_to_bottom
  @selected_index = [agents.length - 1, 0].max
  adjust_scroll
end

#go_to_topObject



43
44
45
46
# File 'lib/binocs/tui/agents_list.rb', line 43

def go_to_top
  @selected_index = 0
  @scroll_offset = 0
end

#load_agentsObject



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

def load_agents
  @agents = Binocs::Agent.all.sort_by(&:created_at).reverse
  @selected_index = [@selected_index, @agents.length - 1].min
  @selected_index = 0 if @selected_index < 0
  adjust_scroll
end

#move_downObject



36
37
38
39
40
41
# File 'lib/binocs/tui/agents_list.rb', line 36

def move_down
  if @selected_index < agents.length - 1
    @selected_index += 1
    adjust_scroll
  end
end

#move_upObject



29
30
31
32
33
34
# File 'lib/binocs/tui/agents_list.rb', line 29

def move_up
  if @selected_index > 0
    @selected_index -= 1
    adjust_scroll
  end
end

#selected_agentObject



25
26
27
# File 'lib/binocs/tui/agents_list.rb', line 25

def selected_agent
  agents[@selected_index]
end