Skip to content

Commit

Permalink
Added home/end functionality
Browse files Browse the repository at this point in the history
Added left/right arrow position checking
  • Loading branch information
james-pre committed Oct 12, 2024
1 parent bb57335 commit 16025ce
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ terminal.onData(data => {
const promptLength = prompt().length;
const x = terminal.buffer.active.cursorX - promptLength;
switch (data) {
case '\x1b[D':
case '\x1b[C':
terminal.write(data);
break;
case 'ArrowUp':
case '\x1b[A':
clear();
Expand All @@ -128,6 +124,22 @@ terminal.onData(data => {
}
terminal.write(input);
break;
case '\x1b[D':
if (x > 0) {
terminal.write(data);
}
break;
case '\x1b[C':
if (x < currentInput.length) {
terminal.write(data);
}
break;
case '\x1b[F':
terminal.write(`\x1b[${promptLength + currentInput.length + 1}G`);
break;
case '\x1b[H':
terminal.write(`\x1b[${promptLength + 1}G`);
break;
case '\x7f':
if (x <= 0) {
return;
Expand All @@ -141,7 +153,7 @@ terminal.onData(data => {
}
index = -1;
input = '';
clear();
terminal.write('\r\n' + prompt());
break;
default:
terminal.write(data);
Expand Down

0 comments on commit 16025ce

Please sign in to comment.