Class: Reline::KeyActor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/reline/key_actor/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(mappings = nil) ⇒ Base

Returns a new instance of Base.



2
3
4
5
6
# File 'lib/reline/key_actor/base.rb', line 2

def initialize(mappings = nil)
  @matching_bytes = {}
  @key_bindings = {}
  add_mappings(mappings) if mappings
end

Instance Method Details

#add(key, func) ⇒ Object



18
19
20
21
22
23
# File 'lib/reline/key_actor/base.rb', line 18

def add(key, func)
  (1...key.size).each do |size|
    @matching_bytes[key.take(size)] = true
  end
  @key_bindings[key] = func
end

#add_mappings(mappings) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/reline/key_actor/base.rb', line 8

def add_mappings(mappings)
  add([27], :ed_ignore)
  128.times do |key|
    func = mappings[key]
    meta_func = mappings[key | 0b10000000]
    add([key], func) if func
    add([27, key], meta_func) if meta_func
  end
end

#clearObject



33
34
35
36
# File 'lib/reline/key_actor/base.rb', line 33

def clear
  @matching_bytes.clear
  @key_bindings.clear
end

#get(key) ⇒ Object



29
30
31
# File 'lib/reline/key_actor/base.rb', line 29

def get(key)
  @key_bindings[key]
end

#matching?(key) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/reline/key_actor/base.rb', line 25

def matching?(key)
  @matching_bytes[key]
end