From 627ced128beeae81540c683861547413a7664d67 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sun, 28 Nov 2010 16:51:25 +0000 Subject: [PATCH] Use a better way to store the attributes for end of line. This should also fix some other bugs, as there were occasionalaccess to out-of-range chars. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39669 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/BasicTerminalBuffer.cpp | 13 ++++++++++--- src/apps/terminal/BasicTerminalBuffer.h | 1 + src/apps/terminal/HistoryBuffer.cpp | 2 ++ src/apps/terminal/TermView.cpp | 21 +++------------------ src/apps/terminal/TerminalLine.h | 5 +++++ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/apps/terminal/BasicTerminalBuffer.cpp b/src/apps/terminal/BasicTerminalBuffer.cpp index 7140fa7453..35887815cc 100644 --- a/src/apps/terminal/BasicTerminalBuffer.cpp +++ b/src/apps/terminal/BasicTerminalBuffer.cpp @@ -240,6 +240,7 @@ BasicTerminalBuffer::SynchronizeWith(const BasicTerminalBuffer* other, if (sourceLine != NULL) { if (sourceLine != destLine) { destLine->length = sourceLine->length; + destLine->attributes = sourceLine->attributes; destLine->softBreak = sourceLine->softBreak; if (destLine->length > 0) { memcpy(destLine->cells, sourceLine->cells, @@ -444,6 +445,14 @@ BasicTerminalBuffer::LineLength(int32 index) const } +int32 +BasicTerminalBuffer::GetLineColor(int32 index) const +{ +// TerminalLine* lineBuffer = ALLOC_LINE_ON_STACK(fWidth); + TerminalLine* line = _LineAt(index); + return line != NULL ? line->attributes : 0; +} + bool BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start, bool forward, bool caseSensitive, bool matchWord, TermPos& _matchStart, @@ -615,10 +624,8 @@ void BasicTerminalBuffer::InsertCR(uint32 attributes) { TerminalLine* line = _LineAt(fCursor.y); - line->cells[fCursor.x].attributes = attributes; - line->cells[fCursor.x].character = ' '; - line->length ++; + line->attributes = attributes; line->softBreak = false; fSoftWrappedCursor = false; fCursor.x = 0; diff --git a/src/apps/terminal/BasicTerminalBuffer.h b/src/apps/terminal/BasicTerminalBuffer.h index f25ec2c6d7..951ce15dc5 100644 --- a/src/apps/terminal/BasicTerminalBuffer.h +++ b/src/apps/terminal/BasicTerminalBuffer.h @@ -92,6 +92,7 @@ public: bool findNonWords, TermPos& start, TermPos& end) const; int32 LineLength(int32 index) const; + int32 GetLineColor(int32 index) const; bool Find(const char* pattern, const TermPos& start, bool forward, bool caseSensitive, diff --git a/src/apps/terminal/HistoryBuffer.cpp b/src/apps/terminal/HistoryBuffer.cpp index ad94f72590..406477422f 100644 --- a/src/apps/terminal/HistoryBuffer.cpp +++ b/src/apps/terminal/HistoryBuffer.cpp @@ -118,6 +118,7 @@ HistoryBuffer::GetTerminalLineAt(int32 index, TerminalLine* buffer) const buffer->length = charCount; buffer->softBreak = line->softBreak; + buffer->attributes = line->attributes; return buffer; } @@ -186,6 +187,7 @@ HistoryBuffer::AddLine(const TerminalLine* line) attributesRun->length = line->length - attributesRun->offset; historyLine->softBreak = line->softBreak; + historyLine->attributes = line->attributes; //debug_printf(" line: \"%.*s\", history size now: %ld\n", historyLine->byteLength, historyLine->Chars(), fSize); } diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index beab93fa7d..3dfa0565f5 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -1428,24 +1428,9 @@ TermView::Draw(BRect updateRect) SetHighColor(fSelectBackColor); FillRect(rect); } else { - // We are not in the selection, so we have to try to - // guess the color for this line from the last char - // that was drawn in it. - int t = 1; - while (count == 0 && i - t >= 0) { - count = fVisibleTextBuffer->GetString( - j - firstVisible, - i - t, lastColumn, buf, attr); - t++; - } - - // If the line is completely empty, we use the default - // back color. - // TODO: It would be better to look at the line above, - // or ensure each line is always initialized with an - // attribute telling wat color to set. - SetHighColor(count ? kTermColorTable[IS_BACKCOLOR(attr)] - : kTermColorTable[0]); + uint32 backcolor = IS_BACKCOLOR(fVisibleTextBuffer->GetLineColor(j)); + rgb_color rgb_back = kTermColorTable[backcolor]; + SetHighColor(rgb_back); FillRect(rect); } diff --git a/src/apps/terminal/TerminalLine.h b/src/apps/terminal/TerminalLine.h index 5a7147de12..dcbca0e5ec 100644 --- a/src/apps/terminal/TerminalLine.h +++ b/src/apps/terminal/TerminalLine.h @@ -7,6 +7,8 @@ #include +#include "TermConst.h" + #include "UTF8Char.h" @@ -19,11 +21,13 @@ struct TerminalCell { struct TerminalLine { uint16 length; bool softBreak; // soft line break + uint32 attributes; TerminalCell cells[1]; inline void Clear() { length = 0; + attributes = 0; softBreak = false; } }; @@ -41,6 +45,7 @@ struct HistoryLine { uint16 attributesRunCount; // number of attribute runs uint16 byteLength : 15; // number of bytes in the line bool softBreak : 1; // soft line break; + uint32 attributes; AttributesRun* AttributesRuns() const {