Class: KeyboardInput

Inherits:
Object
  • 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.



24
25
26
# File 'lib/keyboard_input.rb', line 24

def initialize fella
 @fella = fella
end

Instance Method Details

#get_line_printoutObject



35
36
37
38
39
# File 'lib/keyboard_input.rb', line 35

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

#getchObject



41
42
43
44
# File 'lib/keyboard_input.rb', line 41

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

#handle_keystroke(ch) ⇒ Object



55
56
57
58
# File 'lib/keyboard_input.rb', line 55

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

#handle_keystrokes_foreverObject



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

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



28
29
30
31
32
33
# File 'lib/keyboard_input.rb', line 28

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