diff --git a/src/kit/shell/inc/shellCommand.h b/src/kit/shell/inc/shellCommand.h index a08c1f48d11a8cd0e51fa5fb2d05a16da96d38c9..6e4d3e382e3d7e8c50405c07da8ed73725230434 100644 --- a/src/kit/shell/inc/shellCommand.h +++ b/src/kit/shell/inc/shellCommand.h @@ -35,6 +35,8 @@ struct Command { }; extern void backspaceChar(Command *cmd); +extern void clearLineBefore(Command *cmd); +extern void clearLineAfter(Command *cmd); extern void deleteChar(Command *cmd); extern void moveCursorLeft(Command *cmd); extern void moveCursorRight(Command *cmd); diff --git a/src/kit/shell/src/shellCommand.c b/src/kit/shell/src/shellCommand.c index e1a3dfe10205715d8c5cf8677a5be60c1a478b05..67e0c949890728268afcaf67804dd20e10231ba4 100644 --- a/src/kit/shell/src/shellCommand.c +++ b/src/kit/shell/src/shellCommand.c @@ -102,6 +102,28 @@ void backspaceChar(Command *cmd) { } } +void clearLineBefore(Command *cmd) { + assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset); + + clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size); + memmove(cmd->command, cmd->command + cmd->cursorOffset, + cmd->commandSize - cmd->cursorOffset); + cmd->commandSize -= cmd->cursorOffset; + cmd->cursorOffset = 0; + cmd->screenOffset = 0; + cmd->endOffset = cmd->commandSize; + showOnScreen(cmd); +} + +void clearLineAfter(Command *cmd) { + assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset); + + clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size); + cmd->commandSize -= cmd->endOffset - cmd->cursorOffset; + cmd->endOffset = cmd->cursorOffset; + showOnScreen(cmd); +} + void deleteChar(Command *cmd) { assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset); diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 86c0fea5739ff624cada266e09920f875c24a69a..4dcd8b3d50628f626e681700e131ffb0a3b875e1 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -238,10 +238,16 @@ int32_t shellReadCommand(TAOS *con, char *command) { updateBuffer(&cmd); } break; + case 11: // Ctrl + K; + clearLineAfter(&cmd); + break; case 12: // Ctrl + L; system("clear"); showOnScreen(&cmd); break; + case 21: // Ctrl + U + clearLineBefore(&cmd); + break; } } else if (c == '\033') { c = getchar(); diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 2a32a8d82e73794fbea930c174d6e51f9c194fc3..dc74f6fcaa152c547d734ed4e186b45b94ce8de5 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -238,10 +238,16 @@ int32_t shellReadCommand(TAOS *con, char *command) { updateBuffer(&cmd); } break; + case 11: // Ctrl + K; + clearLineAfter(&cmd); + break; case 12: // Ctrl + L; system("clear"); showOnScreen(&cmd); break; + case 21: // Ctrl + U; + clearLineBefore(&cmd); + break; } } else if (c == '\033') { c = (char)getchar();