Sha256: c11e505a70eea309cdc2e8e28d95135fdfb6be6563fcaef6fe08242552f92d84

Contents?: true

Size: 886 Bytes

Versions: 4

Compression:

Stored size: 886 Bytes

Contents

require_relative 'PromptAction.rb'

#noinspection RubyResolve
module PPCurses

  class GetBooleanAction < PromptAction

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

    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
   

    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

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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ppcurses-0.0.25 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.24 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.23 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.0.22 lib/ppcurses/actions/GetBooleanAction.rb