From f9334b25edffca359292293377cc88ad717151c1 Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Mon, 24 Jan 2022 14:17:38 -0500 Subject: [PATCH] Improve erase characters management --- mentos/src/io/proc_video.c | 3 +-- programs/login.c | 7 +++---- programs/shell.c | 14 +++++++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mentos/src/io/proc_video.c b/mentos/src/io/proc_video.c index 9849f98..ace08fe 100644 --- a/mentos/src/io/proc_video.c +++ b/mentos/src/io/proc_video.c @@ -73,7 +73,6 @@ static ssize_t procv_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyt if (!flg_echoe && flg_echo) { video_puts("^?"); } - // If we are in canonical mode, we pop the previous character. if (flg_icanon) { // Pop the previous character in buffer. @@ -83,7 +82,7 @@ static ssize_t procv_read(vfs_file_t *file, char *buf, off_t offset, size_t nbyt video_putc(c); } else { // Add the character to the buffer. - fs_rb_scancode_push_front(rb, 0x7F); + fs_rb_scancode_push_front(rb, c); // Return the character. *((char *)buf) = fs_rb_scancode_pop_back(rb) & 0x00FF; return 1; diff --git a/programs/login.c b/programs/login.c index 81bd354..3a81d9b 100644 --- a/programs/login.c +++ b/programs/login.c @@ -55,7 +55,7 @@ static bool_t get_input(char *input, size_t max_len, bool_t hide) int c; bool_t result = false; - set_erase(false); + //set_erase(false); if (hide) { set_echo(false); } @@ -100,9 +100,8 @@ static bool_t get_input(char *input, size_t max_len, bool_t hide) } } else if (c == '\b') { if (index > 0) { - if (!hide) { + if (!hide) putchar('\b'); - } --index; } } else { @@ -115,7 +114,7 @@ static bool_t get_input(char *input, size_t max_len, bool_t hide) } } while (index < max_len); - set_erase(true); + //set_erase(true); if (hide) { set_echo(true); putchar('\n'); diff --git a/programs/shell.c b/programs/shell.c index 1a470bc..487faf4 100644 --- a/programs/shell.c +++ b/programs/shell.c @@ -429,12 +429,15 @@ static inline void __cmd_set(char *_cmd) } /// @brief Erases one character from the console. -static inline void __cmd_ers() +static inline void __cmd_ers(char c) { - if (cmd_cursor_index > 0) { + if ((c == '\b') && (cmd_cursor_index > 0)) { strcpy(cmd + cmd_cursor_index - 1, cmd + cmd_cursor_index); putchar('\b'); --cmd_cursor_index; + } else if ((c == 0x7F) && (cmd[0] != 0) && ((cmd_cursor_index + 1) < CMD_LEN)) { + strcpy(cmd + cmd_cursor_index, cmd + cmd_cursor_index + 1); + putchar(0x7F); } } @@ -526,6 +529,11 @@ static void __cmd_get() // Reset the cursor position. cmd_cursor_index += offset; } + } else if (c == '3') { + c = getchar(); // Get the char. + if (c == '~') { + __cmd_ers(0x7F); + } } } else if (c == '^') { c = getchar(); // Get the char. @@ -552,7 +560,7 @@ static void __cmd_get() } } } else if (c == '\b') { - __cmd_ers(); + __cmd_ers('\b'); } else if (c == '\t') { // Get the lenght of the command. size_t cmd_len = strlen(cmd);