Improve erase characters management

This commit is contained in:
Enrico Fraccaroli
2022-01-24 14:17:38 -05:00
parent 30637c3a51
commit f9334b25ed
3 changed files with 15 additions and 9 deletions
+1 -2
View File
@@ -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;
+3 -4
View File
@@ -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');
+11 -3
View File
@@ -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);