Class: TermNote::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/termnote/show.rb,
lib/termnote/show/key.rb

Defined Under Namespace

Modules: Key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShow

Returns a new instance of Show.



8
9
10
# File 'lib/termnote/show.rb', line 8

def initialize
  @panes ||= []
end

Instance Attribute Details

#paneObject



18
19
20
# File 'lib/termnote/show.rb', line 18

def pane
  @pane || panes.first
end

#panesObject

Returns the value of attribute panes.



5
6
7
# File 'lib/termnote/show.rb', line 5

def panes
  @panes
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/termnote/show.rb', line 5

def state
  @state
end

Instance Method Details

#add(pane) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/termnote/show.rb', line 12

def add(pane)
  raise ArgumentError, "Pane required" if pane.nil?
  panes << pane
  pane.show = self
end

#backwardObject



50
51
52
# File 'lib/termnote/show.rb', line 50

def backward
  @pane = panes[position - 1] || panes.last
end

#closeObject



38
39
40
# File 'lib/termnote/show.rb', line 38

def close
  @state = false
end

#forwardObject



46
47
48
# File 'lib/termnote/show.rb', line 46

def forward
  @pane = panes[position + 1] || panes.first
end

#headerObject



42
43
44
# File 'lib/termnote/show.rb', line 42

def header
  "[#{position + 1}/#{total}] - #{panes.first.title}\n".bold
end

#positionObject



22
23
24
# File 'lib/termnote/show.rb', line 22

def position
  panes.index pane
end

#startObject



30
31
32
33
34
35
36
# File 'lib/termnote/show.rb', line 30

def start
  @state = true
  while @state
    pane.call $stdout.winsize
    Key.send @command, self if Key::KEYS.include? capture_command
  end
end

#totalObject



26
27
28
# File 'lib/termnote/show.rb', line 26

def total
  panes.size
end