lib/ruco/keyboard.rb in ruco-0.1.7 vs lib/ruco/keyboard.rb in ruco-0.1.8

- old
+ new

@@ -3,11 +3,11 @@ class Keyboard MAX_CHAR = 255 ENTER = 13 ESCAPE = 27 IS_18 = RUBY_VERSION =~ /^1\.8/ - SEQUENCE_TIMEOUT = 0.02 + SEQUENCE_TIMEOUT = 0.005 NOTHING = (2**32 - 1) # getch returns this as 'nothing' on 1.8 but nil on 1.9.2 A_TO_Z = ('a'..'z').to_a def self.input(&block) @input = block @@ -100,10 +100,14 @@ end def self.fetch_user_input key = @input.call or return key = key.ord if key.is_a?(String) # ruby 1.9 fix - return if key >= NOTHING + if key >= NOTHING + # nothing happening -> sleep a bit to save cpu + sleep SEQUENCE_TIMEOUT + return + end key end def self.append_to_sequence(key) @started = Time.now.to_f