Class: Reline::KeyActor::Base
- Inherits:
-
Object
- Object
- Reline::KeyActor::Base
- Defined in:
- lib/reline/key_actor/base.rb
Instance Method Summary collapse
- #add(key, func) ⇒ Object
- #add_mappings(mappings) ⇒ Object
- #clear ⇒ Object
- #get(key) ⇒ Object
-
#initialize(mappings = nil) ⇒ Base
constructor
A new instance of Base.
- #matching?(key) ⇒ Boolean
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] = mappings[key | 0b10000000] add([key], func) if func add([27, key], ) if end end |
#clear ⇒ Object
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
25 26 27 |
# File 'lib/reline/key_actor/base.rb', line 25 def matching?(key) @matching_bytes[key] end |