Module: Twterm::Tab::Scrollable
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
- #count ⇒ Object
- #draw_scroll_bar ⇒ Object
- #index ⇒ Object
- #initialize ⇒ Object
- #item_appended ⇒ Object
- #item_prepended ⇒ Object
- #last ⇒ Object
- #move_down ⇒ Object
- #move_to_bottom ⇒ Object
- #move_to_top ⇒ Object
- #move_up ⇒ Object
- #offset ⇒ Object
- #offset_from_bottom ⇒ Object
- #respond_to_key(key) ⇒ Object
- #update_scrollbar_length ⇒ Object
Methods included from Base
Instance Method Details
#count ⇒ Object
40 41 42 |
# File 'lib/twterm/tab/scrollable.rb', line 40 def count @scrollable_count end |
#draw_scroll_bar ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/twterm/tab/scrollable.rb', line 115 def return if count == 0 height = @window.maxy top = height * index / count @window.with_color(:black, :white) do @scrollable_scrollbar_length.times do |i| @window.setpos(top + i, @window.maxx - 1) @window.addch(' ') end end end |
#index ⇒ Object
36 37 38 |
# File 'lib/twterm/tab/scrollable.rb', line 36 def index @scrollable_index end |
#initialize ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/twterm/tab/scrollable.rb', line 6 def initialize super @scrollable_index = 0 @scrollable_count = 0 @scrollable_offset = 0 @scrollable_last = 0 @scrollable_scrollbar_length = 0 end |
#item_appended ⇒ Object
58 59 60 61 62 |
# File 'lib/twterm/tab/scrollable.rb', line 58 def item_appended @scrollable_index -= 1 @scrollable_offset -= 1 if @scrollable_offset > 0 end |
#item_prepended ⇒ Object
52 53 54 55 56 |
# File 'lib/twterm/tab/scrollable.rb', line 52 def item_prepended @scrollable_index += 1 @scrollable_offset += 1 end |
#last ⇒ Object
48 49 50 |
# File 'lib/twterm/tab/scrollable.rb', line 48 def last @scrollable_last end |
#move_down ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/twterm/tab/scrollable.rb', line 72 def move_down return if count == 0 || index == count - 1 @scrollable_index = [index + 1, count - 1].min @scrollable_offset = [ offset + 1, count - 1, count - offset_from_bottom ].min if index > last - 4 refresh end |
#move_to_bottom ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/twterm/tab/scrollable.rb', line 93 def move_to_bottom return if count == 0 || index == count - 1 @scrollable_index = count - 1 @scrollable_offset = count - 1 - offset_from_bottom refresh end |
#move_to_top ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/twterm/tab/scrollable.rb', line 85 def move_to_top return if count == 0 || index == 0 @scrollable_index = 0 @scrollable_offset = 0 refresh end |
#move_up ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/twterm/tab/scrollable.rb', line 64 def move_up return if count == 0 || index == 0 @scrollable_index = [index - 1, 0].max @scrollable_offset = [offset - 1, 0].max if index - 4 < offset refresh end |
#offset ⇒ Object
44 45 46 |
# File 'lib/twterm/tab/scrollable.rb', line 44 def offset @scrollable_offset end |
#offset_from_bottom ⇒ Object
101 102 103 |
# File 'lib/twterm/tab/scrollable.rb', line 101 def offset_from_bottom 0 end |
#respond_to_key(key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/twterm/tab/scrollable.rb', line 16 def respond_to_key(key) case key when 'g' move_to_top when 'G' move_to_bottom when 'j', 14, Key::DOWN move_down when 'k', 16, Key::UP move_up when 'd', 4 10.times { move_down } when 'u', 21 10.times { move_up } else return false end true end |
#update_scrollbar_length ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/twterm/tab/scrollable.rb', line 105 def @scrollable_scrollbar_length = if count == 0 0 else height = @window.maxy [height * (last - index + 1) / count, 1].max end end |