diff --git a/lib/src/embedded_cli.c b/lib/src/embedded_cli.c index 549bb29..e91a267 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); + } } } @@ -878,12 +901,7 @@ static void parseCommand(EmbeddedCli *cli) { embeddedCliTokenizeArgs(cmdArgs); // currently, output is blank line, so we can just print directly SET_FLAG(impl->flags, CLI_FLAG_DIRECT_PRINT); - // check if help was requested (help is printed when no other options are set) - if (cmdArgs != NULL && (strcmp(cmdArgs, "-h") == 0 || strcmp(cmdArgs, "--help") == 0)) { - printBindingHelp(cli, &impl->bindings[i]); - } else { - impl->bindings[i].binding(cli, cmdArgs, impl->bindings[i].context); - } + impl->bindings[i].binding(cli, cmdArgs, impl->bindings[i].context); UNSET_U8FLAG(impl->flags, CLI_FLAG_DIRECT_PRINT); return; }