Class: Alchemist::Curses::PromptWindow

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

Instance Method Summary collapse

Constructor Details

#initialize(line, col, width) ⇒ PromptWindow

Returns a new instance of PromptWindow.



6
7
8
# File 'lib/alchemist-server/curses/prompt_window.rb', line 6

def initialize(line, col, width)
  @win = newwin 1, width, line, col
end

Instance Method Details

#ask(label) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alchemist-server/curses/prompt_window.rb', line 10

def ask(label)
  wclear @win
  wmove @win, 0, 0
  wprintw @win, label
  wprintw @win, ': '
  wrefresh @win

  answer = ''

  while (c = wgetch @win) != "\n".ord
    if c > 0
      answer << c
      wprintw @win, (''<<c)
    end

    wrefresh @win
  end

  wclear @win

  answer.strip
end