Sha256: a1f4f7d90158dd0e7a7d0842098e40bd6d55b500862a597b3325ce9479e9f712

Contents?: true

Size: 921 Bytes

Versions: 3

Compression:

Stored size: 921 Bytes

Contents

require "curses"

class GetBooleanAction < PromptAction

  def initialize(prompt) 
    super(prompt)
    @state = false;
  end

  def printPrompt()
    super()
    @win.addstr("No [")
    if (@state == false) then @win.addstr("X") else @win.addstr(" ") end
    @win.addstr("] Yes [")
    if (@state == true) then @win.addstr("X") else @win.addstr(" ") end
    @win.addstr("]")
  end
 

  def execute()
    printPrompt()
    # 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
      printPrompt()
    end
    echo
    # Go to next line so that further actions to overwrite
    # the choice
    @win.setpos(@win.cury() + 1, @parent.winPadding())
  end

  def data
    if @state == false then return "0" end
    "1"
  end 

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ppcurses-0.0.10 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.9 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.8 lib/ppcurses/actions/GetBooleanAction.rb