diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 71c2e63..0793cc4 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -5,8 +5,36 @@ char inputBuffer[256]; uint8_t inputBufferPosition; +bool printInput = true; -void onKeyInput(uint32_t keycode, uint32_t stringId) { printf("%c", keycode); } +void onNewLine() { + printf("\nInput: %s\n> ", inputBuffer); + inputBufferPosition = 0; + inputBuffer[inputBufferPosition] = '\0'; +} + +void onKeyInput(uint32_t keycode, uint32_t stringId) { + switch (keycode) { + case '\b': + if (inputBufferPosition) { + inputBufferPosition--; + inputBuffer[inputBufferPosition] = 0; + printf("\b"); + } + break; + case '\n': + onNewLine(); + break; + default: + if (printInput) { + printf("%c", keycode); + } + inputBuffer[inputBufferPosition] = (char)keycode; + inputBufferPosition++; + inputBuffer[inputBufferPosition] = '\0'; + break; + } +} int32_t main() { createFunction("onKey", (void *)onKeyInput); diff --git a/src/userland/shell/main.c b/src/userland/shell/main.c index 71c2e63..0793cc4 100644 --- a/src/userland/shell/main.c +++ b/src/userland/shell/main.c @@ -5,8 +5,36 @@ char inputBuffer[256]; uint8_t inputBufferPosition; +bool printInput = true; -void onKeyInput(uint32_t keycode, uint32_t stringId) { printf("%c", keycode); } +void onNewLine() { + printf("\nInput: %s\n> ", inputBuffer); + inputBufferPosition = 0; + inputBuffer[inputBufferPosition] = '\0'; +} + +void onKeyInput(uint32_t keycode, uint32_t stringId) { + switch (keycode) { + case '\b': + if (inputBufferPosition) { + inputBufferPosition--; + inputBuffer[inputBufferPosition] = 0; + printf("\b"); + } + break; + case '\n': + onNewLine(); + break; + default: + if (printInput) { + printf("%c", keycode); + } + inputBuffer[inputBufferPosition] = (char)keycode; + inputBufferPosition++; + inputBuffer[inputBufferPosition] = '\0'; + break; + } +} int32_t main() { createFunction("onKey", (void *)onKeyInput); diff --git a/src/userland/vga/main.c b/src/userland/vga/main.c index ec1eb13..067ef5a 100644 --- a/src/userland/vga/main.c +++ b/src/userland/vga/main.c @@ -22,6 +22,11 @@ case '\n': offset = (offset / WIDTH + 1) * WIDTH; return; + case '\b': + offset--; + writeChar(' ', COLOR(white, black)); + offset--; + return; } writeChar(c, COLOR(white, black)); }