Class: Keyboard

Inherits:
Object show all
Defined in:
lib/ruco/keyboard.rb

Constant Summary collapse

SWAP_DELETE =
(ENV['TERM'] == 'xterm-color')
MAX_CHAR =
255
ENTER =
13
ESCAPE =
27
IS_18 =
RUBY_VERSION =~ /^1\.8/
SEQUENCE_TIMEOUT =
0.01
NOTHING =

getch returns this as ‘nothing’ on 1.8 but nil on 1.9.2

(2**32 - 1)
A_TO_Z =
('a'..'z').to_a

Class Method Summary collapse

Class Method Details

.input(&block) ⇒ Object



13
14
15
# File 'lib/ruco/keyboard.rb', line 13

def self.input(&block)
  @input = block
end

.outputObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ruco/keyboard.rb', line 17

def self.output
  @sequence = []
  @started = Time.now.to_f

  loop do
    key = fetch_user_input
    if sequence_finished?
      sequence_to_keys(@sequence).each{|k| yield k }
      @sequence = []
    end
    next unless key
    append_to_sequence key
  end
end