Skip to content

Commit f8e3059

Browse files
committed
feat: add home, end, and delete cursor functionality
1 parent 8734a57 commit f8e3059

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/src/embedded_cli.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,29 @@ static void onEscapedInput(EmbeddedCli *cli, char c) {
760760
impl->cursorPos++;
761761
writeToOutput(cli, escSeqCursorLeft);
762762
}
763+
764+
// Home
765+
if (c == 'H' || (c == '~' && (impl->lastChar == '1' || impl->lastChar == '7'))) {
766+
if (impl->cursorPos < impl->cmdSize) {
767+
moveCursor(cli, impl->cmdSize - impl->cursorPos, CURSOR_DIRECTION_BACKWARD);
768+
impl->cursorPos = impl->cmdSize;
769+
}
770+
}
771+
// End
772+
if (c == 'F' || (c == '~' && (impl->lastChar == '4' || impl->lastChar == '8'))) {
773+
if (impl->cursorPos > 0) {
774+
moveCursor(cli, impl->cursorPos, CURSOR_DIRECTION_FORWARD);
775+
impl->cursorPos = 0;
776+
}
777+
}
778+
// Delete
779+
if (c == '~' && impl->lastChar == '3' && impl->cursorPos > 0) {
780+
size_t insertPos = strlen(impl->cmdBuffer) - impl->cursorPos;
781+
memmove(&impl->cmdBuffer[insertPos], &impl->cmdBuffer[insertPos + 1], impl->cursorPos);
782+
--impl->cmdSize;
783+
--impl->cursorPos;
784+
writeToOutput(cli, escSeqDeleteChar);
785+
}
763786
}
764787
}
765788

0 commit comments

Comments
 (0)