Class: Kward::NativeShell::ViEditor
- Inherits:
-
Object
- Object
- Kward::NativeShell::ViEditor
- Defined in:
- lib/kward/shell/native_vi.rb
Overview
Character-oriented vi edit state. IO/raw mode and command execution belong to the standalone runner; history copies never mutate retained entries.
Defined Under Namespace
Classes: InvalidCommand, Result
Constant Summary collapse
- MOTIONS =
" hl0^$|wWbBeEfFtT;,".freeze
- MAX_MACRO_DEPTH =
100- MAX_MACRO_BYTES =
1_048_576- CHANGES =
"aAiIRcdCDSrxXpP~_*\\".freeze
Instance Method Summary collapse
- #encoding ⇒ Object
-
#initialize(runtime) ⇒ ViEditor
constructor
A new instance of ViEditor.
- #read(get:, changed:, alert:, erase: TerminalKeys::BACKSPACE.last, kill: TerminalKeys::CTRL_U, eof: TerminalKeys::CTRL_D, interrupt: TerminalKeys::CTRL_C, draft: nil) ⇒ Object
Constructor Details
#initialize(runtime) ⇒ ViEditor
Returns a new instance of ViEditor.
17 18 19 20 |
# File 'lib/kward/shell/native_vi.rb', line 17 def initialize(runtime) @runtime = runtime @saved = "" end |
Instance Method Details
#encoding ⇒ Object
22 23 24 |
# File 'lib/kward/shell/native_vi.rb', line 22 def encoding @locale.encoding end |
#read(get:, changed:, alert:, erase: TerminalKeys::BACKSPACE.last, kill: TerminalKeys::CTRL_U, eof: TerminalKeys::CTRL_D, interrupt: TerminalKeys::CTRL_C, draft: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 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 65 66 |
# File 'lib/kward/shell/native_vi.rb', line 26 def read(get:, changed:, alert:, erase: TerminalKeys::BACKSPACE.last, kill: TerminalKeys::CTRL_U, eof: TerminalKeys::CTRL_D, interrupt: TerminalKeys::CTRL_C, draft: nil) @get, @changed, @alert = get, changed, alert @erase, @kill, @eof, @interrupt = erase, kill, eof, interrupt @line, @draft, @original = +"", +"", +"" @position = 0 @history_index = entries.length @insert = @initial = true @replace = false @queue = [] @recording = @undo = nil @macro_bytes = 0 Locale.with(@runtime.variables) do |locale| @locale = locale @line = draft.to_s.b.force_encoding(locale.encoding).scrub @position = @line.length loop do @changed.call(@line, @position) key = input return nil unless key raise Interrupt if key == @interrupt if @insert if TerminalKeys::RETURN.include?(key) @recording[-1] = TerminalKeys::ESCAPE if @recording finish_change return Result.new(text: @line + "\n") end return nil if key == @eof && @line.empty? insert_key(key) else return Result.new(text: @line + "\n") if TerminalKeys::RETURN.include?(key) result = command(key) return result if result end rescue InvalidCommand, SyntaxError, ExpansionError, ExecutionError, ArgumentError, RangeError, SystemCallError, IOError @recording = nil @alert.call end end ensure @locale = @get = @changed = @alert = nil end |