From a43a4e9fbf97c030f53fab0c610b54e640df1545 Mon Sep 17 00:00:00 2001 From: Jessica Hamilton Date: Tue, 26 Apr 2022 09:50:11 +1200 Subject: [PATCH] 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. --- src/apps/terminal/HistoryBuffer.cpp | 8 ++++++-- src/apps/terminal/TerminalLine.h | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/apps/terminal/HistoryBuffer.cpp b/src/apps/terminal/HistoryBuffer.cpp index 2a85e4823c..c947f8ab61 100644 --- a/src/apps/terminal/HistoryBuffer.cpp +++ b/src/apps/terminal/HistoryBuffer.cpp @@ -146,8 +146,10 @@ HistoryBuffer::AddLine(const TerminalLine* line) for (int32 i = 0; i < line->length; i++) { const TerminalCell& cell = line->cells[i]; byteLength += cell.character.ByteCount(); - if ((cell.attributes.state & CHAR_ATTRIBUTES) != attributes.state) { + if (cell != attributes) { attributes.state = cell.attributes.state & CHAR_ATTRIBUTES; + attributes.foreground = cell.attributes.foreground; + attributes.background = cell.attributes.background; if (attributes.state != 0) attributesRuns++; } @@ -173,7 +175,7 @@ HistoryBuffer::AddLine(const TerminalLine* line) chars += charLength; // deal with attributes - if ((cell.attributes.state & CHAR_ATTRIBUTES) != attributes.state) { + if (cell != attributes) { // terminate the previous attributes run if (attributes.state != 0) { attributesRun->length = i - attributesRun->offset; @@ -181,6 +183,8 @@ HistoryBuffer::AddLine(const TerminalLine* line) } attributes.state = cell.attributes.state & CHAR_ATTRIBUTES; + attributes.foreground = cell.attributes.foreground; + attributes.background = cell.attributes.background; // init the new one if (attributes.state != 0) { diff --git a/src/apps/terminal/TerminalLine.h b/src/apps/terminal/TerminalLine.h index abdc25a276..0f5e5cfa49 100644 --- a/src/apps/terminal/TerminalLine.h +++ b/src/apps/terminal/TerminalLine.h @@ -134,6 +134,15 @@ struct Attributes { struct TerminalCell { UTF8Char character; 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; + } };