Class: InteractiveScrollArea
- Inherits:
-
Object
- Object
- InteractiveScrollArea
- Defined in:
- lib/terminal-scroll-area/interactive_scroll_area.rb
Overview
Interactice scroll area which scrolls and reprints the content in response to user pressing arrow keys.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#height ⇒ Object
Returns the value of attribute height.
-
#scroll_area ⇒ Object
Returns the value of attribute scroll_area.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #add_string(string) ⇒ Object
-
#initialize(width, height) ⇒ InteractiveScrollArea
constructor
A new instance of InteractiveScrollArea.
- #keydown(_event) ⇒ Object
- #keyleft(_event) ⇒ Object
- #keyright(_event) ⇒ Object
- #keyup(_event) ⇒ Object
- #scroll ⇒ Object
Constructor Details
#initialize(width, height) ⇒ InteractiveScrollArea
Returns a new instance of InteractiveScrollArea.
13 14 15 16 17 18 19 20 21 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 13 def initialize(width, height) @width = width @height = height @scroll_area = ScrollArea.new(@width, @height) @reader = TTY::Reader.new(interrupt: :exit) @reader.subscribe(self) end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 10 def content @content end |
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 11 def height @height end |
#scroll_area ⇒ Object
Returns the value of attribute scroll_area.
11 12 13 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 11 def scroll_area @scroll_area end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 11 def width @width end |
Instance Method Details
#add_line(line) ⇒ Object
40 41 42 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 40 def add_line(line) @scroll_area.add_line(line) end |
#add_string(string) ⇒ Object
36 37 38 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 36 def add_string(string) @scroll_area.add_string(string) end |
#keydown(_event) ⇒ Object
44 45 46 47 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 44 def keydown(_event) @scroll_area.scroll_down print_in_place(@scroll_area.render) end |
#keyleft(_event) ⇒ Object
59 60 61 62 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 59 def keyleft(_event) @scroll_area.scroll_left print_in_place(@scroll_area.render) end |
#keyright(_event) ⇒ Object
54 55 56 57 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 54 def keyright(_event) @scroll_area.scroll_right print_in_place(@scroll_area.render) end |
#keyup(_event) ⇒ Object
49 50 51 52 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 49 def keyup(_event) @scroll_area.scroll_up print_in_place(@scroll_area.render) end |
#scroll ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/terminal-scroll-area/interactive_scroll_area.rb', line 23 def scroll print_in_place(@scroll_area.render) TTY::Cursor.invisible do loop do @reader.read_keypress end end end |