Class: Rereline::KeyStroke
- Inherits:
-
Object
- Object
- Rereline::KeyStroke
- Defined in:
- lib/rereline/key_stroke.rb
Defined Under Namespace
Modules: Ex
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
- #expand(input, wait_match: true) ⇒ Object
-
#initialize(mapping) ⇒ KeyStroke
constructor
A new instance of KeyStroke.
Constructor Details
#initialize(mapping) ⇒ KeyStroke
Returns a new instance of KeyStroke.
37 38 39 |
# File 'lib/rereline/key_stroke.rb', line 37 def initialize(mapping) @mapping = mapping end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
35 36 37 |
# File 'lib/rereline/key_stroke.rb', line 35 def mapping @mapping end |
Instance Method Details
#expand(input, wait_match: true) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rereline/key_stroke.rb', line 41 def (input, wait_match: true) if input.empty? [[], []] elsif wait_match && matching?(input) [[], input] elsif matched?(input) lhs, rhs = mapping.filter { |lhs, rhs| lhs.matched? input }.max_by { |lhs, rhs| lhs.size } if (after_input = input.drop(lhs.size)).size > 0 # NOTE: 再帰的にマッピングされているキーを展開する時に後続のキーが存在している場合は待ち処理はせずに展開する join((rhs, wait_match: false), (after_input, wait_match: wait_match)) else (rhs, wait_match: wait_match) end else join([input.take(1), []], (input.drop(1), wait_match: wait_match)) end end |