From f8e30592eefbaf53af2ba3abf259218f7ecb7055 Mon Sep 17 00:00:00 2001 From: gary7530 Date: Mon, 15 Dec 2025 15:49:57 +0800 Subject: [PATCH 1/2] feat: add home, end, and delete cursor functionality --- lib/src/embedded_cli.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/src/embedded_cli.c b/lib/src/embedded_cli.c index 549bb29..85a2dbb 100644 --- a/lib/src/embedded_cli.c +++ b/lib/src/embedded_cli.c @@ -760,6 +760,29 @@ static void onEscapedInput(EmbeddedCli *cli, char c) { impl->cursorPos++; writeToOutput(cli, escSeqCursorLeft); } + + // Home + if (c == 'H' || (c == '~' && (impl->lastChar == '1' || impl->lastChar == '7'))) { + if (impl->cursorPos < impl->cmdSize) { + moveCursor(cli, impl->cmdSize - impl->cursorPos, CURSOR_DIRECTION_BACKWARD); + impl->cursorPos = impl->cmdSize; + } + } + // End + if (c == 'F' || (c == '~' && (impl->lastChar == '4' || impl->lastChar == '8'))) { + if (impl->cursorPos > 0) { + moveCursor(cli, impl->cursorPos, CURSOR_DIRECTION_FORWARD); + impl->cursorPos = 0; + } + } + // Delete + if (c == '~' && impl->lastChar == '3' && impl->cursorPos > 0) { + size_t insertPos = strlen(impl->cmdBuffer) - impl->cursorPos; + memmove(&impl->cmdBuffer[insertPos], &impl->cmdBuffer[insertPos + 1], impl->cursorPos); + --impl->cmdSize; + --impl->cursorPos; + writeToOutput(cli, escSeqDeleteChar); + } } } From a3e3adf5381064acb17d5b52f01550e4d34884cc Mon Sep 17 00:00:00 2001 From: gary7530 Date: Mon, 15 Dec 2025 21:55:09 +0800 Subject: [PATCH 2/2] docs: update README with cursor navigation and deletion controls --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 40d1cc6..76a7812 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,9 @@ Terminal is required for correct experience. Following control sequences are res * \t moves cursor to the end of autocompleted command * Esc[A (key up) and Esc[B (key down) navigates through history * Esc[C (key right) and Esc[D (key left) moves the cursor left and right +* Esc[H (Home) or Esc[1~ / Esc[7~ moves the cursor to the start of the line +* Esc[F (End) or Esc[4~ / Esc[8~ moves the cursor to the end of the line +* Esc[3~ (Delete) deletes the character at the cursor position If you run CLI through a serial port (like on Arduino with its UART-USB converter), you can use for example PuTTY (Windows) or XTerm (Linux).