Class: Foruiman::TUI::Viewport

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Viewport

Returns a new instance of Viewport.



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

def initialize
  @following = true
  @anchor = nil
end

Instance Attribute Details

#anchor ⇒ Object (readonly)

Returns the value of attribute anchor.



5
6
7
# File 'lib/foruiman/tui/viewport.rb', line 5

def anchor
  @anchor
end

#following ⇒ Object (readonly)

Returns the value of attribute following.



5
6
7
# File 'lib/foruiman/tui/viewport.rb', line 5

def following
  @following
end

Instance Method Details

#follow ⇒ Object



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

def follow
  @following = true
  @anchor = nil
end

#home(buffer) ⇒ Object



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

def home(buffer)
  @following = false
  @anchor = buffer[0]&.sequence
end

#rows(buffer, height) ⇒ Object



12
13
14
15
16
# File 'lib/foruiman/tui/viewport.rb', line 12

def rows(buffer, height)
  height = [height, 0].max
  start = top(buffer, height)
  Array.new([height, buffer.size - start].min) { |offset| buffer[start + offset] }
end

#scroll(delta, buffer, height) ⇒ Object



18
19
20
21
22
# File 'lib/foruiman/tui/viewport.rb', line 18

def scroll(delta, buffer, height)
  index = top(buffer, height)
  @following = false
  set_anchor(index + delta, buffer, height)
end

#toggle(buffer, height) ⇒ Object



34
35
36
# File 'lib/foruiman/tui/viewport.rb', line 34

def toggle(buffer, height)
  following ? scroll(0, buffer, height) : follow
end