module Canis::Keyboard

Constants

ASCII

TODO: make this section sane

CONTROL
CONTROL_KEYS
ESC
MOD_KEYS
NCURSES_KEYS
PRINTABLE
PRINTABLE_KEYS
SPECIAL_KEYS

Public Instance Methods

focus=(receiver) click to toggle source
# File lib/canis/core/system/deprecated/keyboard.rb, line 8
def focus=(receiver)
  @stack = []
  @focus = receiver
  poll unless @polling
end
poll() click to toggle source
# File lib/canis/core/system/deprecated/keyboard.rb, line 14
    def poll
      @polling = true

      while char = @focus.window.getch
        break if @focus.stopping? # XXX
        #break if VER.stopping?
        $log.debug("char: #{char} stakc: #{@stack.inspect}") if char != Ncurses::ERR
        if char == Ncurses::ERR # timeout or signal
          @focus.press('esc') if @stack == [ESC]
          @stack.clear
        elsif ready = resolve(char)
$log.debug("char: #{char} ready: #{ready}")
          @stack.clear
          @focus.press(ready)
        end
      end

    ensure
      @polling = false
    end
resolve(char) click to toggle source
# File lib/canis/core/system/deprecated/keyboard.rb, line 35
def resolve(char)
  @stack << char

  if @stack.first == ESC
    MOD_KEYS[@stack] || SPECIAL_KEYS[@stack]
  else
    NCURSES_KEYS[char] || CONTROL_KEYS[char] || PRINTABLE_KEYS[char]
  end
end