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
This commit is contained in:
Bananymous 2023-03-22 02:09:22 +02:00
parent b222581d18
commit 2ec18855f2
2 changed files with 23 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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<uint32_t>(m_height, new_height); y++)
for (uint32_t x = 0; x < BAN::Math::min<uint32_t>(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);