From 4ffc69a6e4bb5d685bc2ccc165fd979a5bf0ffe2 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 22 Mar 2023 02:09:22 +0200 Subject: [PATCH] Kernel: TTY buffer is resized on font size change Shell also has better line wrapping. You still can't visually go back to previous line, but atleas we now write from the beginning of the line --- kernel/kernel/Shell.cpp | 2 +- kernel/kernel/TTY.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/kernel/kernel/Shell.cpp b/kernel/kernel/Shell.cpp index be87003147..a95bcee31d 100644 --- a/kernel/kernel/Shell.cpp +++ b/kernel/kernel/Shell.cpp @@ -606,7 +606,7 @@ argument_done: } } - TTY_PRINT("\e[{}G", m_prompt_length + m_cursor_pos.col + 1); + TTY_PRINT("\e[{}G", (m_prompt_length + m_cursor_pos.col) % m_tty->width() + 1); } } \ No newline at end of file diff --git a/kernel/kernel/TTY.cpp b/kernel/kernel/TTY.cpp index 1fdb899f3d..41eaf069ee 100644 --- a/kernel/kernel/TTY.cpp +++ b/kernel/kernel/TTY.cpp @@ -55,6 +55,28 @@ void TTY::set_cursor_position(uint32_t x, uint32_t y) void TTY::set_font(const Kernel::Font& font) { m_terminal_driver->set_font(font); + + uint32_t new_width = m_terminal_driver->width(); + uint32_t new_height = m_terminal_driver->height(); + + if (m_width != new_width || m_height != new_height) + { + Cell* new_buffer = new Cell[new_width * new_height]; + ASSERT(new_buffer); + + for (uint32_t i = 0; i < new_width * m_height; i++) + new_buffer[i] = { .foreground = m_foreground, .background = m_background, .character = ' ' }; + + for (uint32_t y = 0; y < BAN::Math::min(m_height, new_height); y++) + for (uint32_t x = 0; x < BAN::Math::min(m_width, new_width); x++) + new_buffer[y * new_width + x] = m_buffer[y * m_width + x]; + + delete[] m_buffer; + m_buffer = new_buffer; + m_width = new_width; + m_height = new_height; + } + for (uint32_t y = 0; y < m_height; y++) for (uint32_t x = 0; x < m_width; x++) render_from_buffer(x, y);