Class: Foruiman::TUI::State

Inherits:
Object
  • Object
show all
Defined in:
lib/foruiman/tui/state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(names) ⇒ State

Returns a new instance of State.



11
12
13
14
15
16
17
18
19
# File 'lib/foruiman/tui/state.rb', line 11

def initialize(names)
  @tabs = [*names, :all].freeze
  @selected = tabs.size - 1
  @viewports = tabs.to_h { |name| [name, Viewport.new] }
  @help = false
  @feedback = nil
  @input_target = nil
  @input_lines = names.to_h { |name| [name, InputLine.new] }
end

Instance Attribute Details

#feedback ⇒ Object

Returns the value of attribute feedback.



9
10
11
# File 'lib/foruiman/tui/state.rb', line 9

def feedback
  @feedback
end

#help ⇒ Object

Returns the value of attribute help.



9
10
11
# File 'lib/foruiman/tui/state.rb', line 9

def help
  @help
end

#input_target ⇒ Object

Returns the value of attribute input_target.



9
10
11
# File 'lib/foruiman/tui/state.rb', line 9

def input_target
  @input_target
end

#selected ⇒ Object (readonly)

Returns the value of attribute selected.



8
9
10
# File 'lib/foruiman/tui/state.rb', line 8

def selected
  @selected
end

#tabs ⇒ Object (readonly)

Returns the value of attribute tabs.



8
9
10
# File 'lib/foruiman/tui/state.rb', line 8

def tabs
  @tabs
end

#viewports ⇒ Object (readonly)

Returns the value of attribute viewports.



8
9
10
# File 'lib/foruiman/tui/state.rb', line 8

def viewports
  @viewports
end

Instance Method Details

#aggregate? ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/foruiman/tui/state.rb', line 25

def aggregate?
  name == :all
end

#input? ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/foruiman/tui/state.rb', line 33

def input?
  !input_target.nil?
end

#input_line ⇒ Object



37
38
39
# File 'lib/foruiman/tui/state.rb', line 37

def input_line
  @input_lines.fetch(input_target || name)
end

#move(delta) ⇒ Object



45
46
47
# File 'lib/foruiman/tui/state.rb', line 45

def move(delta)
  @selected = (selected + delta) % tabs.size
end

#name ⇒ Object



21
22
23
# File 'lib/foruiman/tui/state.rb', line 21

def name
  tabs[selected]
end

#select(index) ⇒ Object



41
42
43
# File 'lib/foruiman/tui/state.rb', line 41

def select(index)
  @selected = index if index.between?(0, tabs.size - 1)
end

#viewport ⇒ Object



29
30
31
# File 'lib/foruiman/tui/state.rb', line 29

def viewport
  viewports.fetch(name)
end