Class: RuVim::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/ruvim/input.rb

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Input

Returns a new instance of Input.



5
6
7
# File 'lib/ruvim/input.rb', line 5

def initialize(input)
  @input = input
end

Instance Method Details

#has_pending_input?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ruvim/input.rb', line 45

def has_pending_input?
  IO.select([@input], nil, nil, 0) != nil
end

#read_key(timeout: nil, wakeup_ios: [], esc_timeout: nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ruvim/input.rb', line 9

def read_key(timeout: nil, wakeup_ios: [], esc_timeout: nil)
  ios = [@input, *wakeup_ios].compact
  readable = IO.select(ios, nil, nil, timeout)
  return nil unless readable

  ready = readable[0]
  wakeups = ready - [@input]
  wakeups.each { |io| drain_io(io) }
  return nil unless ready.include?(@input)

  ch = @input.getch
  case ch
  when "\u0002" then :ctrl_b
  when "\u0003" then :ctrl_c
  when "\u0004" then :ctrl_d
  when "\u0005" then :ctrl_e
  when "\u0006" then :ctrl_f
  when "\u0007" then :ctrl_g
  when "\u0009" then :ctrl_i
  when "\u000c" then :ctrl_l
  when "\u000e" then :ctrl_n
  when "\u000f" then :ctrl_o
  when "\u0010" then :ctrl_p
  when "\u0012" then :ctrl_r
  when "\u0015" then :ctrl_u
  when "\u0016" then :ctrl_v
  when "\u0017" then :ctrl_w
  when "\u0019" then :ctrl_y
  when "\u001a" then :ctrl_z
  when "\r", "\n" then :enter
  when "\u007f", "\b" then :backspace
  when "\e" then read_escape_sequence(timeout: esc_timeout)
  else ch
  end
end