Class: PPCurses::GetBooleanAction

Inherits:
PromptAction show all
Defined in:
lib/ppcurses/actions/GetBooleanAction.rb

Instance Method Summary collapse

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

#dataObject



41
42
43
44
# File 'lib/ppcurses/actions/GetBooleanAction.rb', line 41

def data
  if @state then return '1' end
  '0'
end

#executeObject



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


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