Class: PPCurses::GetBooleanAction
- Inherits:
-
PromptAction
- Object
- BaseAction
- PromptAction
- PPCurses::GetBooleanAction
- Defined in:
- lib/ppcurses/actions/GetBooleanAction.rb
Instance Method Summary collapse
- #data ⇒ Object
- #execute ⇒ Object
-
#initialize(prompt) ⇒ GetBooleanAction
constructor
A new instance of GetBooleanAction.
- #print_prompt ⇒ Object
Methods inherited from PromptAction
#set_parent_action, #x_padding
Methods inherited from BaseAction
#create_window, #set_window, #show, #win_height, #win_padding, #win_width, #x_padding
Constructor Details
#initialize(prompt) ⇒ GetBooleanAction
Returns a new instance of GetBooleanAction.
8 9 10 11 |
# File 'lib/ppcurses/actions/GetBooleanAction.rb', line 8 def initialize(prompt) super(prompt) @state = false end |
Instance Method Details
#data ⇒ Object
41 42 43 44 |
# File 'lib/ppcurses/actions/GetBooleanAction.rb', line 41 def data if @state then return '1' end '0' end |
#execute ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ppcurses/actions/GetBooleanAction.rb', line 23 def execute print_prompt # Enables reading arrow keys in getch @win.keypad(true) while 1 noecho c = @win.getch if c == KEY_LEFT then @state = false end if c == KEY_RIGHT then @state = true end if c == 10 then break end echo print_prompt end echo end |
#print_prompt ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ppcurses/actions/GetBooleanAction.rb', line 13 def print_prompt super() @win.addstr('No [') if @state then @win.addstr(' ') else @win.addstr('X') end @win.addstr('] Yes [') if @state then @win.addstr('X') else @win.addstr(' ') end @win.addstr(']') end |