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
This commit is contained in:
Adrien Destugues
2010-11-28 16:51:25 +00:00
parent e55a3c6a38
commit 627ced128b
5 changed files with 21 additions and 21 deletions
+10 -3
View File
@@ -240,6 +240,7 @@ BasicTerminalBuffer::SynchronizeWith(const BasicTerminalBuffer* other,
if (sourceLine != NULL) { if (sourceLine != NULL) {
if (sourceLine != destLine) { if (sourceLine != destLine) {
destLine->length = sourceLine->length; destLine->length = sourceLine->length;
destLine->attributes = sourceLine->attributes;
destLine->softBreak = sourceLine->softBreak; destLine->softBreak = sourceLine->softBreak;
if (destLine->length > 0) { if (destLine->length > 0) {
memcpy(destLine->cells, sourceLine->cells, 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 bool
BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start, BasicTerminalBuffer::Find(const char* _pattern, const TermPos& start,
bool forward, bool caseSensitive, bool matchWord, TermPos& _matchStart, bool forward, bool caseSensitive, bool matchWord, TermPos& _matchStart,
@@ -615,10 +624,8 @@ void
BasicTerminalBuffer::InsertCR(uint32 attributes) BasicTerminalBuffer::InsertCR(uint32 attributes)
{ {
TerminalLine* line = _LineAt(fCursor.y); TerminalLine* line = _LineAt(fCursor.y);
line->cells[fCursor.x].attributes = attributes;
line->cells[fCursor.x].character = ' ';
line->length ++;
line->attributes = attributes;
line->softBreak = false; line->softBreak = false;
fSoftWrappedCursor = false; fSoftWrappedCursor = false;
fCursor.x = 0; fCursor.x = 0;
+1
View File
@@ -92,6 +92,7 @@ public:
bool findNonWords, TermPos& start, bool findNonWords, TermPos& start,
TermPos& end) const; TermPos& end) const;
int32 LineLength(int32 index) const; int32 LineLength(int32 index) const;
int32 GetLineColor(int32 index) const;
bool Find(const char* pattern, const TermPos& start, bool Find(const char* pattern, const TermPos& start,
bool forward, bool caseSensitive, bool forward, bool caseSensitive,
+2
View File
@@ -118,6 +118,7 @@ HistoryBuffer::GetTerminalLineAt(int32 index, TerminalLine* buffer) const
buffer->length = charCount; buffer->length = charCount;
buffer->softBreak = line->softBreak; buffer->softBreak = line->softBreak;
buffer->attributes = line->attributes;
return buffer; return buffer;
} }
@@ -186,6 +187,7 @@ HistoryBuffer::AddLine(const TerminalLine* line)
attributesRun->length = line->length - attributesRun->offset; attributesRun->length = line->length - attributesRun->offset;
historyLine->softBreak = line->softBreak; historyLine->softBreak = line->softBreak;
historyLine->attributes = line->attributes;
//debug_printf(" line: \"%.*s\", history size now: %ld\n", historyLine->byteLength, historyLine->Chars(), fSize); //debug_printf(" line: \"%.*s\", history size now: %ld\n", historyLine->byteLength, historyLine->Chars(), fSize);
} }
+3 -18
View File
@@ -1428,24 +1428,9 @@ TermView::Draw(BRect updateRect)
SetHighColor(fSelectBackColor); SetHighColor(fSelectBackColor);
FillRect(rect); FillRect(rect);
} else { } else {
// We are not in the selection, so we have to try to uint32 backcolor = IS_BACKCOLOR(fVisibleTextBuffer->GetLineColor(j));
// guess the color for this line from the last char rgb_color rgb_back = kTermColorTable[backcolor];
// that was drawn in it. SetHighColor(rgb_back);
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]);
FillRect(rect); FillRect(rect);
} }
+5
View File
@@ -7,6 +7,8 @@
#include <SupportDefs.h> #include <SupportDefs.h>
#include "TermConst.h"
#include "UTF8Char.h" #include "UTF8Char.h"
@@ -19,11 +21,13 @@ struct TerminalCell {
struct TerminalLine { struct TerminalLine {
uint16 length; uint16 length;
bool softBreak; // soft line break bool softBreak; // soft line break
uint32 attributes;
TerminalCell cells[1]; TerminalCell cells[1];
inline void Clear() inline void Clear()
{ {
length = 0; length = 0;
attributes = 0;
softBreak = false; softBreak = false;
} }
}; };
@@ -41,6 +45,7 @@ struct HistoryLine {
uint16 attributesRunCount; // number of attribute runs uint16 attributesRunCount; // number of attribute runs
uint16 byteLength : 15; // number of bytes in the line uint16 byteLength : 15; // number of bytes in the line
bool softBreak : 1; // soft line break; bool softBreak : 1; // soft line break;
uint32 attributes;
AttributesRun* AttributesRuns() const AttributesRun* AttributesRuns() const
{ {