Module: Remedy::Keyboard

Defined in:
lib/remedy/keyboard.rb

Defined Under Namespace

Classes: ControlC, UnrecognizedInput

Class Method Summary collapse

Class Method Details

.dont_raise_on_control_c!Object



59
60
61
# File 'lib/remedy/keyboard.rb', line 59

def dont_raise_on_control_c!
  @raise_on_control_c = false
end

.dont_raise_on_unrecognized_key!Object



47
48
49
# File 'lib/remedy/keyboard.rb', line 47

def dont_raise_on_unrecognized_key!
  @raise_on_unrecognized_key = false
end

.getObject



8
9
10
# File 'lib/remedy/keyboard.rb', line 8

def get
  parse raw_get
end

.parse(sequence) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/remedy/keyboard.rb', line 25

def parse sequence
  key = Key.new sequence

  if raise_on_control_c? && key.control_c? then
    raise ControlC, "User pressed Control-C"
  elsif key.recognized? then
    key
  elsif raise_on_unrecognized_key? then
    raise UnrecognizedInput, %Q{Unknown key or byte sequence: "#{sequence}" : #{key.inspect}}
  else
    key
  end
end

.raise_on_control_c!Object



55
56
57
# File 'lib/remedy/keyboard.rb', line 55

def raise_on_control_c!
  @raise_on_control_c = true
end

.raise_on_control_c?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/remedy/keyboard.rb', line 51

def raise_on_control_c?
  @raise_on_control_c
end

.raise_on_unrecognized_key!Object



43
44
45
# File 'lib/remedy/keyboard.rb', line 43

def raise_on_unrecognized_key!
  @raise_on_unrecognized_key = true
end

.raise_on_unrecognized_key?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/remedy/keyboard.rb', line 39

def raise_on_unrecognized_key?
  @raise_on_unrecognized_key
end

.raw_getObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/remedy/keyboard.rb', line 12

def raw_get
  Console.raw do
    input = STDIN.getc.chr

    if input == "\e" then
      input << STDIN.read_nonblock(3) rescue nil
      input << STDIN.read_nonblock(2) rescue nil
    end

    input
  end
end