Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
23 changes: 23 additions & 0 deletions lib/src/embedded_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down