Sha256: 8fde76165d06fdeaa90af869e9c51839ee58335bd4a1b48a54e37260aaccf86b

Contents?: true

Size: 905 Bytes

Versions: 5

Compression:

Stored size: 905 Bytes

Contents

require 'ppcurses/actions/PromptAction.rb'

module PPCurses

  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
    end

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

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ppcurses-0.0.15 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.14 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.13 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.12 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.11 lib/ppcurses/actions/GetBooleanAction.rb