diff --git a/src/module/repl.wren b/src/module/repl.wren index eec22036..668f271f 100644 --- a/src/module/repl.wren +++ b/src/module/repl.wren @@ -71,6 +71,15 @@ class Repl { deleteLeft() } else if (byte >= Chars.space && byte <= Chars.tilde) { insertChar(byte) + } else if (byte == Chars.ctrlW) { // Handle Ctrl+w + // Delete trailing spaces + while (_cursor != 0 && _line[_cursor - 1] == " ") { + deleteLeft() + } + // Delete until the next space + while (_cursor != 0 && _line[_cursor - 1] != " ") { + deleteLeft() + } } else { // TODO: Other shortcuts? System.print("Unhandled key-code [dec]: %(byte)") @@ -108,6 +117,14 @@ class Repl { previousHistory() } else if (byte == EscapeBracket.down) { nextHistory() + } else if (byte == EscapeBracket.delete) { + deleteRight() + // Consume extra 126 character generated by delete + Stdin.readByte() + } else if (byte == EscapeBracket.end) { + _cursor = _line.count + } else if (byte == EscapeBracket.home) { + _cursor = 0 } } @@ -403,6 +420,7 @@ class Chars { static ctrlN { 0x0e } static ctrlP { 0x10 } static ctrlU { 0x15 } + static ctrlW { 0x17 } static escape { 0x1b } static space { 0x20 } static bang { 0x21 } @@ -470,10 +488,13 @@ class Chars { } class EscapeBracket { + static delete { 0x33 } static up { 0x41 } static down { 0x42 } static right { 0x43 } static left { 0x44 } + static end { 0x46 } + static home { 0x48 } } class Token {