Terminal: fix missing attribute state for the history buffer.

* This presented itself as 24-bit colour rendering as white on black
  when scrolling through the history.
This commit is contained in:
Jessica Hamilton 2022-04-26 09:50:11 +12:00
parent 07b83028cd
commit a43a4e9fbf
2 changed files with 15 additions and 2 deletions

View File

@ -146,8 +146,10 @@ HistoryBuffer::AddLine(const TerminalLine* line)
for (int32 i = 0; i < line->length; i++) { for (int32 i = 0; i < line->length; i++) {
const TerminalCell& cell = line->cells[i]; const TerminalCell& cell = line->cells[i];
byteLength += cell.character.ByteCount(); byteLength += cell.character.ByteCount();
if ((cell.attributes.state & CHAR_ATTRIBUTES) != attributes.state) { if (cell != attributes) {
attributes.state = cell.attributes.state & CHAR_ATTRIBUTES; attributes.state = cell.attributes.state & CHAR_ATTRIBUTES;
attributes.foreground = cell.attributes.foreground;
attributes.background = cell.attributes.background;
if (attributes.state != 0) if (attributes.state != 0)
attributesRuns++; attributesRuns++;
} }
@ -173,7 +175,7 @@ HistoryBuffer::AddLine(const TerminalLine* line)
chars += charLength; chars += charLength;
// deal with attributes // deal with attributes
if ((cell.attributes.state & CHAR_ATTRIBUTES) != attributes.state) { if (cell != attributes) {
// terminate the previous attributes run // terminate the previous attributes run
if (attributes.state != 0) { if (attributes.state != 0) {
attributesRun->length = i - attributesRun->offset; attributesRun->length = i - attributesRun->offset;
@ -181,6 +183,8 @@ HistoryBuffer::AddLine(const TerminalLine* line)
} }
attributes.state = cell.attributes.state & CHAR_ATTRIBUTES; attributes.state = cell.attributes.state & CHAR_ATTRIBUTES;
attributes.foreground = cell.attributes.foreground;
attributes.background = cell.attributes.background;
// init the new one // init the new one
if (attributes.state != 0) { if (attributes.state != 0) {

View File

@ -134,6 +134,15 @@ struct Attributes {
struct TerminalCell { struct TerminalCell {
UTF8Char character; UTF8Char character;
Attributes attributes; Attributes attributes;
inline bool
operator!=(const Attributes& other) const
{
return (attributes.state & CHAR_ATTRIBUTES)
!= (other.state & CHAR_ATTRIBUTES)
|| attributes.foreground != other.foreground
|| attributes.background != other.background;
}
}; };