diff --git a/kernel/kernel/Terminal/Serial.cpp b/kernel/kernel/Terminal/Serial.cpp index 8f92668a..200f42cb 100644 --- a/kernel/kernel/Terminal/Serial.cpp +++ b/kernel/kernel/Terminal/Serial.cpp @@ -210,6 +210,8 @@ namespace Kernel void SerialTTY::handle_irq() { uint8_t ch = IO::inb(m_serial.port()); + if (ch == 0x7F) + ch = '\b'; SpinLockGuard _(m_input_lock); if (m_input.full()) diff --git a/kernel/kernel/Terminal/TTY.cpp b/kernel/kernel/Terminal/TTY.cpp index e8c26f25..18ee4bf7 100644 --- a/kernel/kernel/Terminal/TTY.cpp +++ b/kernel/kernel/Terminal/TTY.cpp @@ -285,14 +285,6 @@ namespace Kernel void TTY::do_backspace() { - auto print_backspace = - [this] - { - putchar('\b'); - putchar(' '); - putchar('\b'); - }; - if (m_output.bytes > 0) { uint8_t last = m_output.buffer[m_output.bytes - 1]; @@ -308,20 +300,20 @@ namespace Kernel } ASSERT(m_output.bytes > 0); m_output.bytes--; - print_backspace(); + putchar('\b'); } // Caret notation else if (last < 32 || last == 127) { m_output.bytes--; - print_backspace(); - print_backspace(); + putchar('\b'); + putchar('\b'); } // Ascii else { m_output.bytes--; - print_backspace(); + putchar('\b'); } } } diff --git a/kernel/kernel/Terminal/VirtualTTY.cpp b/kernel/kernel/Terminal/VirtualTTY.cpp index b4e6f755..8ef3c172 100644 --- a/kernel/kernel/Terminal/VirtualTTY.cpp +++ b/kernel/kernel/Terminal/VirtualTTY.cpp @@ -461,7 +461,7 @@ namespace Kernel break; case BS: if (m_column > 0) - m_column--; + putchar_at(' ', --m_column, m_row); break; case HT: m_column++; @@ -480,7 +480,7 @@ namespace Kernel break; case ESC: m_state = State::WaitingAnsiEscape; - break;; + break; default: putchar_at(codepoint, m_column, m_row); m_last_graphic_char = codepoint; diff --git a/userspace/libraries/LibInput/KeyEvent.cpp b/userspace/libraries/LibInput/KeyEvent.cpp index 9f836310..b183f014 100644 --- a/userspace/libraries/LibInput/KeyEvent.cpp +++ b/userspace/libraries/LibInput/KeyEvent.cpp @@ -58,10 +58,10 @@ namespace LibInput "å", "ä", "ö", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ", + /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", "!", "\"", "#", "¤", "%", "&", "/", "§", "½", "(", ")", "[", "]", "{", "}", - "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "€", + "=", "?", "+", "\\", "´", "`", "¨", "¸", "\b", "@", "£", "$", "€", "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", @@ -77,10 +77,10 @@ namespace LibInput "Å", "Ä", "Ö", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ", + /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", "!", "\"", "#", "¤", "%", "&", "/", "§", "½", "(", ")", "[", "]", "{", "}", - "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "€", + "=", "?", "+", "\\", "´", "`", "¨", "¸", "\b", "@", "£", "$", "€", "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", @@ -96,10 +96,10 @@ namespace LibInput "Å", "Ä", "Ö", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, - /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\e[3~", nullptr, nullptr, nullptr, nullptr, "\n", " ", + /*"Insert", "PrintScreen", "Delete", "Home", "End", "PageUp", "PageDown",*/ nullptr, nullptr, "\x7F", nullptr, nullptr, nullptr, nullptr, "\n", " ", "!", "\"", "#", "¤", "%", "&", "/", "§", "½", "(", ")", "[", "]", "{", "}", - "=", "?", "+", "\\", "´", "`", "¨", "¸", "\x7F", "@", "£", "$", "€", + "=", "?", "+", "\\", "´", "`", "¨", "¸", "\b", "@", "£", "$", "€", "\e", "\t", nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, "'", "*", "^", "~", "\e[A", "\e[B", "\e[D", "\e[C", ",", ";", ".", ":", "-", "_", nullptr, nullptr, "<", ">", "|", "¬", "¦", diff --git a/userspace/programs/Shell/Input.cpp b/userspace/programs/Shell/Input.cpp index 16e7535d..909c6d85 100644 --- a/userspace/programs/Shell/Input.cpp +++ b/userspace/programs/Shell/Input.cpp @@ -468,9 +468,9 @@ BAN::Optional Input::get_input(BAN::Optional custo if (m_buffer_col <= 0) break; while ((m_buffers[m_buffer_index][m_buffer_col - 1] & 0xC0) == 0x80) - m_buffer_col--; - m_buffer_col--; - printf("\e[D"); + m_buffers[m_buffer_index].remove(--m_buffer_col); + m_buffers[m_buffer_index].remove(--m_buffer_col); + printf("\b\e[s%s \e[u", m_buffers[m_buffer_index].data() + m_buffer_col); fflush(stdout); break; case '\x01': // ^A @@ -490,13 +490,13 @@ BAN::Optional Input::get_input(BAN::Optional custo break; putchar('\n'); return {}; - case '\x7F': // backspace - if (m_buffer_col <= 0) + case '\x7F': + if (m_buffer_col >= m_buffers[m_buffer_index].size()) break; - while ((m_buffers[m_buffer_index][m_buffer_col - 1] & 0xC0) == 0x80) - m_buffers[m_buffer_index].remove(--m_buffer_col); - m_buffers[m_buffer_index].remove(--m_buffer_col); - printf("\b\e[s%s \e[u", m_buffers[m_buffer_index].data() + m_buffer_col); + m_buffers[m_buffer_index].remove(m_buffer_col); + while (m_buffer_col < m_buffers[m_buffer_index].size() && (m_buffers[m_buffer_index][m_buffer_col] & 0xC0) == 0x80) + m_buffers[m_buffer_index].remove(m_buffer_col); + printf("\e[s%s \e[u", m_buffers[m_buffer_index].data() + m_buffer_col); fflush(stdout); break; case '\n':