Class: Alchemist::Curses::MessagesWindow
- Includes:
- FFI::NCurses
- Defined in:
- lib/alchemist-server/curses/messages_window.rb
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(height, width, line, col) ⇒ MessagesWindow
constructor
A new instance of MessagesWindow.
- #messages_to_show ⇒ Object
- #scroll_down ⇒ Object
- #scroll_up ⇒ Object
- #update(messages) ⇒ Object
Constructor Details
#initialize(height, width, line, col) ⇒ MessagesWindow
Returns a new instance of MessagesWindow.
6 7 8 9 10 11 12 13 14 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 6 def initialize(height, width, line, col) @height = height @width = width @offset = 0 @messages = [] @win = newwin height, width, line, col end |
Instance Method Details
#draw ⇒ Object
16 17 18 19 20 21 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 16 def draw wmove @win, 0, 0 wclear @win wprintw @win, .join("\n") wrefresh @win end |
#messages_to_show ⇒ Object
23 24 25 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 23 def @messages[@offset,@height] || [] end |
#scroll_down ⇒ Object
37 38 39 40 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 37 def scroll_down @offset = [@offset+1, @messages.length - height].min draw end |
#scroll_up ⇒ Object
32 33 34 35 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 32 def scroll_up @offset = [@offset-1, 0].max draw end |
#update(messages) ⇒ Object
27 28 29 30 |
# File 'lib/alchemist-server/curses/messages_window.rb', line 27 def update() @messages = draw end |