Fix backspace emulation in the serial console and in fgets()

This commit is contained in:
Ali Mashtizadeh 2023-09-22 21:07:27 -04:00
parent fe1f411bdc
commit 56bef77cce
2 changed files with 11 additions and 0 deletions

View File

@ -171,6 +171,11 @@ fgets(char *str, int size, FILE *fh)
int ch = fgetc(fh);
if (ch == EOF)
return NULL;
if (ch == '\b') {
if (i > 0)
i -= 2;
continue;
}
str[i] = (char)ch;
if (ch == '\n') {
str[i + 1] = '\0';

View File

@ -91,6 +91,12 @@ void Serial_Putc(char ch)
// Timeout!
}
outb(base + UART_OFFSET_DATA, ch);
if (ch == '\b') {
Serial_Putc(0x1B);
Serial_Putc('[');
Serial_Putc('P');
}
}
void Serial_Puts(const char *str)