Terminal: Reallocate kept lines when resizing the terminal.
Otherwise we end up with garbage text when making the window bigger.
This commit is contained in:
parent
e8f35ef311
commit
6e4f0b3cc5
Notes:
sideshowbarker
2024-07-19 13:43:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/6e4f0b3cc57
2 changed files with 27 additions and 12 deletions
|
@ -68,12 +68,9 @@ Terminal::Terminal(int ptm_fd, RetainPtr<CConfigFile> config)
|
|||
m_config->read_num_entry("Window", "Height", 25));
|
||||
}
|
||||
|
||||
Terminal::Line::Line(word columns)
|
||||
: length(columns)
|
||||
Terminal::Line::Line(word length)
|
||||
{
|
||||
characters = new byte[length];
|
||||
attributes = new Attribute[length];
|
||||
memset(characters, ' ', length);
|
||||
set_length(length);
|
||||
}
|
||||
|
||||
Terminal::Line::~Line()
|
||||
|
@ -82,20 +79,34 @@ Terminal::Line::~Line()
|
|||
delete[] attributes;
|
||||
}
|
||||
|
||||
void Terminal::Line::set_length(word new_length)
|
||||
{
|
||||
if (m_length == new_length)
|
||||
return;
|
||||
auto* new_characters = new byte[new_length];
|
||||
auto* new_attributes = new Attribute[new_length];
|
||||
memset(new_characters, ' ', new_length);
|
||||
delete[] characters;
|
||||
delete[] attributes;
|
||||
characters = new_characters;
|
||||
attributes = new_attributes;
|
||||
m_length = new_length;
|
||||
}
|
||||
|
||||
void Terminal::Line::clear(Attribute attribute)
|
||||
{
|
||||
if (dirty) {
|
||||
memset(characters, ' ', length);
|
||||
for (word i = 0; i < length; ++i)
|
||||
memset(characters, ' ', m_length);
|
||||
for (word i = 0; i < m_length; ++i)
|
||||
attributes[i] = attribute;
|
||||
return;
|
||||
}
|
||||
for (unsigned i = 0; i < length; ++i) {
|
||||
for (unsigned i = 0; i < m_length; ++i) {
|
||||
if (characters[i] != ' ')
|
||||
dirty = true;
|
||||
characters[i] = ' ';
|
||||
}
|
||||
for (unsigned i = 0; i < length; ++i) {
|
||||
for (unsigned i = 0; i < m_length; ++i) {
|
||||
if (attributes[i] != attribute)
|
||||
dirty = true;
|
||||
attributes[i] = attribute;
|
||||
|
@ -877,6 +888,9 @@ void Terminal::set_size(word columns, word rows)
|
|||
m_lines.resize(rows);
|
||||
}
|
||||
|
||||
for (int i = 0; i < rows; ++i)
|
||||
m_lines[i]->set_length(columns);
|
||||
|
||||
m_columns = columns;
|
||||
m_rows = rows;
|
||||
|
||||
|
@ -927,11 +941,11 @@ Rect Terminal::row_rect(word row)
|
|||
|
||||
bool Terminal::Line::has_only_one_background_color() const
|
||||
{
|
||||
if (!length)
|
||||
if (!m_length)
|
||||
return true;
|
||||
// FIXME: Cache this result?
|
||||
auto color = attributes[0].background_color;
|
||||
for (size_t i = 1; i < length; ++i) {
|
||||
for (size_t i = 1; i < m_length; ++i) {
|
||||
if (attributes[i].background_color != color)
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -127,10 +127,11 @@ private:
|
|||
~Line();
|
||||
void clear(Attribute);
|
||||
bool has_only_one_background_color() const;
|
||||
void set_length(word);
|
||||
byte* characters { nullptr };
|
||||
Attribute* attributes { nullptr };
|
||||
bool dirty { false };
|
||||
word length { 0 };
|
||||
word m_length { 0 };
|
||||
};
|
||||
Line& line(size_t index)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue