Sha256: e4fbe0e0d3c5db942f6adcf47ac87984f73c63b2e26f0bc1e40fa0e90b891d63

Contents?: true

Size: 927 Bytes

Versions: 2

Compression:

Stored size: 927 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
        Curses.noecho
        c = @win.getch

        if c == Curses::KEY_LEFT then @state = false end
        if c == Curses::KEY_RIGHT then @state = true end
        if c == ESCAPE then break end

        Curses.echo
        print_prompt
      end
      Curses.echo
    end

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

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ppcurses-0.1.1 lib/ppcurses/actions/GetBooleanAction.rb
ppcurses-0.1.0 lib/ppcurses/actions/GetBooleanAction.rb