Class: PM::PromptWindow
- Inherits:
-
Object
- Object
- PM::PromptWindow
- Includes:
- Curses
- Defined in:
- lib/patchmaster/curses/prompt_window.rb
Constant Summary collapse
- MAX_WIDTH =
30
Instance Method Summary collapse
- #cleanup ⇒ Object
- #draw ⇒ Object
- #gets ⇒ Object
-
#initialize(title, prompt) ⇒ PromptWindow
constructor
A new instance of PromptWindow.
- #read_string ⇒ Object
Constructor Details
#initialize(title, prompt) ⇒ PromptWindow
Returns a new instance of PromptWindow.
10 11 12 13 14 15 |
# File 'lib/patchmaster/curses/prompt_window.rb', line 10 def initialize(title, prompt) @title, @prompt = title, prompt width = cols() / 2 width = MAX_WIDTH if width > MAX_WIDTH @win = Window.new(4, width, lines() / 3, (cols() - width) / 2) end |
Instance Method Details
#cleanup ⇒ Object
57 58 59 |
# File 'lib/patchmaster/curses/prompt_window.rb', line 57 def cleanup @win.close end |
#draw ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/patchmaster/curses/prompt_window.rb', line 24 def draw @win.box(?|, ?-) @win.setpos(0, 1) @win.attron(A_REVERSE) { @win.addstr(" #@title ") } @win.setpos(1, 1) @win.addstr(@prompt) @win.setpos(2, 1) @win.attron(A_REVERSE) { @win.addstr(' ' * (@win.maxx() - 2)) } @win.setpos(2, 1) @win.refresh end |
#gets ⇒ Object
17 18 19 20 21 22 |
# File 'lib/patchmaster/curses/prompt_window.rb', line 17 def gets draw str = read_string cleanup str end |
#read_string ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/patchmaster/curses/prompt_window.rb', line 43 def read_string nocbreak echo curs_set(1) str = nil @win.attron(A_REVERSE) { str = @win.getstr } curs_set(0) noecho cbreak str end |