Class: HandyToolbox::Scroll
- Inherits:
-
Object
- Object
- HandyToolbox::Scroll
- Defined in:
- lib/handy_toolbox/scroll.rb
Instance Attribute Summary collapse
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
- #down(by = 1) ⇒ Object
- #fits_into_pane?(y) ⇒ Boolean
-
#initialize ⇒ Scroll
constructor
A new instance of Scroll.
- #reset ⇒ Object
- #to(index) ⇒ Object
- #to_first ⇒ Object
- #to_last ⇒ Object
- #up(by = 1) ⇒ Object
- #update(max_y) ⇒ Object
Constructor Details
#initialize ⇒ Scroll
Returns a new instance of Scroll.
7 8 9 10 11 |
# File 'lib/handy_toolbox/scroll.rb', line 7 def initialize @screen = Curses.stdscr @screen.scrollok(true) reset end |
Instance Attribute Details
#top ⇒ Object (readonly)
Returns the value of attribute top.
5 6 7 |
# File 'lib/handy_toolbox/scroll.rb', line 5 def top @top end |
Instance Method Details
#down(by = 1) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/handy_toolbox/scroll.rb', line 34 def down(by = 1) by = max_top - @top if @top + by > max_top if by > 0 screen.scrl(by) @top += by end end |
#fits_into_pane?(y) ⇒ Boolean
22 23 24 |
# File 'lib/handy_toolbox/scroll.rb', line 22 def fits_into_pane?(y) (y - top) >= 0 && (y - top) < screen.maxy end |
#reset ⇒ Object
13 14 15 16 |
# File 'lib/handy_toolbox/scroll.rb', line 13 def reset @top = 0 @max_y = 0 end |
#to(index) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/handy_toolbox/scroll.rb', line 42 def to(index) if index != top if index >= 0 && index <= max_top by = index - top screen.scrl(by) @top = index elsif index < 0 to_first elsif index > max_top to_last end end end |
#to_first ⇒ Object
56 57 58 |
# File 'lib/handy_toolbox/scroll.rb', line 56 def to_first to(0) end |
#to_last ⇒ Object
60 61 62 |
# File 'lib/handy_toolbox/scroll.rb', line 60 def to_last to(max_top) end |
#up(by = 1) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/handy_toolbox/scroll.rb', line 26 def up(by = 1) by = @top if @top - by < 0 if by > 0 screen.scrl(-by) @top -= by end end |
#update(max_y) ⇒ Object
18 19 20 |
# File 'lib/handy_toolbox/scroll.rb', line 18 def update(max_y) @max_y = max_y end |