Class: KeyboardInput

Inherits:
Object show all
Defined in:
lib/keyboard_input.rb

Overview

does the jruby check inline

Instance Method Summary collapse

Constructor Details

#initialize(fella) ⇒ KeyboardInput

Returns a new instance of KeyboardInput.



26
27
28
# File 'lib/keyboard_input.rb', line 26

def initialize fella
 @fella = fella
end

Instance Method Details

#get_line_printoutObject



37
38
39
40
41
# File 'lib/keyboard_input.rb', line 37

def get_line_printout
   status  = @fella.status
   # some scary hard coded values here...LODO curses?
   " " * 20 + "\b"*150 + status
end

#getchObject



43
44
45
46
# File 'lib/keyboard_input.rb', line 43

def getch
 @getch ||= Win32API.new('crtdll', '_getch', [], 'L')
 @getch.call
end

#handle_keystroke(ch) ⇒ Object



57
58
59
60
# File 'lib/keyboard_input.rb', line 57

def handle_keystroke ch
  string = "" << ch
  @fella.keyboard_input(string)
end

#handle_keystrokes_foreverObject



48
49
50
51
52
53
54
55
# File 'lib/keyboard_input.rb', line 48

def handle_keystrokes_forever
  raise 'only jruby supported, as it looks just too messy in normal ruby' unless OS.java?
  while(ch = getch)
    exit if ch == 3 # ctrl+c
    # lodo handle arrow keys, too, which is a bit more complicated...
    handle_keystroke ch
  end
end

#start_threadObject



30
31
32
33
34
35
# File 'lib/keyboard_input.rb', line 30

def start_thread
 Thread.new { loop { 
   print get_line_printout
   sleep 0.1
  } }
end