Class: Alchemist::Curses::MessagesWindow

Inherits:
Object
  • Object
show all
Includes:
FFI::NCurses
Defined in:
lib/alchemist-server/curses/messages_window.rb

Instance Method Summary collapse

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

#drawObject



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, messages_to_show.join("\n")
  wrefresh @win
end

#messages_to_showObject



23
24
25
# File 'lib/alchemist-server/curses/messages_window.rb', line 23

def messages_to_show
  @messages[@offset,@height] || []
end

#scroll_downObject



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_upObject



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)
  @messages = messages
  draw
end