Class: Interface
- Inherits:
-
Object
- Object
- Interface
- Defined in:
- lib/live_sql/interface.rb
Instance Attribute Summary collapse
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
-
#get_keyboard_input ⇒ Object
oringal case statement from: www.alecjacobson.com/weblog/?p=75.
- #read_char ⇒ Object
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
4 5 6 |
# File 'lib/live_sql/interface.rb', line 4 def string @string end |
Instance Method Details
#get_keyboard_input ⇒ Object
oringal case statement from: www.alecjacobson.com/weblog/?p=75
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/live_sql/interface.rb', line 25 def get_keyboard_input c = read_char case c when "\r" :error when "\e" :quit when "\e[C" "RIGHT ARROW" :right when "\e[D" "LEFT ARROW" :left when "\177" :backspace when "\004" :delete when "\e[3~" :delete when /^.$/ c else :error end end |
#read_char ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/live_sql/interface.rb', line 6 def read_char STDIN.echo = false STDIN.raw! input = STDIN.getc.chr if input == "\e" then input << STDIN.read_nonblock(3) rescue nil input << STDIN.read_nonblock(2) rescue nil end ensure STDIN.echo = true STDIN.cooked! return input end |