Class: TermNote::Show

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShow

Returns a new instance of Show.



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

def initialize
  @panes ||= []
end

Instance Attribute Details

#panesObject

Returns the value of attribute panes.



3
4
5
# File 'lib/termnote/show.rb', line 3

def panes
  @panes
end

Instance Method Details

#add(pane) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/termnote/show.rb', line 9

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

#backwardObject



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

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

#forwardObject



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

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

#headerObject



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

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

#paneObject



15
16
17
# File 'lib/termnote/show.rb', line 15

def pane
  @pane || panes.first
end

#positionObject



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

def position
  panes.index pane
end

#startObject



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

def start
  active = true
  while active
    pane.call $stdout.winsize
    case command
      when "j" then forward
      when "k" then backward
      when "q" then active = false
    end
  end
end

#totalObject



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

def total
  panes.size
end