Class: Vice::Parser
- Inherits:
-
Object
- Object
- Vice::Parser
- Defined in:
- lib/vice/parser.rb
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parsechar_command(vice, current_buffer, char) ⇒ Object
- #parsechar_insert(vice, current_buffer, char) ⇒ Object
- #parsechar_prompt(vice, current_buffer, char) ⇒ Object
- #parsekeypress(vice, buffer, char) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
2 3 4 |
# File 'lib/vice/parser.rb', line 2 def initialize @current_command = '' end |
Instance Method Details
#parsechar_command(vice, current_buffer, char) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vice/parser.rb', line 38 def parsechar_command(vice, current_buffer, char) buffer = vice.buffers[current_buffer] raise 'command parser called from wrong mode' unless vice.mode == :command if %i[mark_set mark_jump].include? @current_command Vice::KeyPress.public_send(@current_command, vice, buffer, char) @current_command = '' return end @current_command += char if !vice.config[:keys][@current_command].nil? command = vice.config[:keys][@current_command] if %i[mark_set mark_jump].include? command @current_command = command else Vice::KeyPress.public_send(command, vice, buffer) @current_command = '' end else keep_current = false vice.config[:keys].each do |k| keep_current = true if k[0].start_with? @current_command end @current_command = '' unless keep_current end end |
#parsechar_insert(vice, current_buffer, char) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/vice/parser.rb', line 66 def parsechar_insert(vice, current_buffer, char) buffer = vice.buffers[current_buffer] raise 'insert parser called from wrong mode' unless vice.mode == :insert case char when 9 buffer.insert "\t" buffer.cursor.col += 1 when 10 # return buffer.newline buffer.cursor.line + 1 buffer.cursor_down when 27 # escape vice.mode = :command buffer.cursor_end_of_line when 127 # backspace if buffer.cursor.col.positive? buffer.cursor.col -= 1 buffer.rmchar end when Integer vice.prompt += char if char >= 0 && char <= 10 else buffer.insert char buffer.cursor.col += 1 end end |
#parsechar_prompt(vice, current_buffer, char) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vice/parser.rb', line 18 def parsechar_prompt(vice, current_buffer, char) raise 'prompt parser called from wrong mode' unless vice.mode == :prompt case char when 10 # enter Vice::Prompt.parse vice, vice.prompt, vice.buffers[current_buffer] vice.prompt = '' vice.mode = :command when 27 # escape vice.prompt = '' vice.mode = :command when 127 # backspace vice.prompt = vice.prompt[0..-2] when Integer vice.prompt += char if char >= 0 && char <= 10 else vice.prompt += char end end |
#parsekeypress(vice, buffer, char) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/vice/parser.rb', line 6 def parsekeypress(vice, buffer, char) if vice.mode == :command parsechar_command vice, buffer, char elsif vice.mode == :insert parsechar_insert vice, buffer, char elsif vice.mode == :prompt parsechar_prompt vice, buffer, char else raise 'parsekeypress called with unknown mode' end end |