Class: MiniTerm::Mapper
- Inherits:
-
Object
- Object
- MiniTerm::Mapper
- Defined in:
- lib/mini_term/common/mapper.rb
Overview
Translate raw input to mapped commands.
Instance Method Summary collapse
-
#[]=(indexes, value) ⇒ Object
Add a map entry.
-
#get_mapped_char ⇒ Object
Get a mapped input sequence.
-
#initialize {|_self| ... } ⇒ Mapper
constructor
Set up the keystroke mapper.
-
#process_non_terminals(index) ⇒ Object
Handle the preamble characters in the command sequence.
Constructor Details
Instance Method Details
#[]=(indexes, value) ⇒ Object
Add a map entry
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mini_term/common/mapper.rb', line 16 def []=(indexes, value) indexes = [indexes] unless indexes.is_a?(Range) indexes.each do |index| process_non_terminals(index) if @map.has_key?(index) fail MiniTermKME, "Duplicate entry #{index.inspect}" end @map[index] = [value, index] end end |
#get_mapped_char ⇒ Object
Get a mapped input sequence.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mini_term/common/mapper.rb', line 46 def get_mapped_char key_seq, key_cmd = "", nil begin key_seq << yield key_cmd = @map[key_seq] end until key_cmd key_cmd end |
#process_non_terminals(index) ⇒ Object
Handle the preamble characters in the command sequence.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mini_term/common/mapper.rb', line 31 def process_non_terminals(index) seq = "" index.chop.chars.each do |char| seq << char if @map.has_key?(seq) && @map[seq] fail MiniTermKME, "Ambiguous entry #{index.inspect}" end @map[seq] = false end end |