[haiku-commits] r39669 - haiku/trunk/src/apps/terminal

  • From: pulkomandy@xxxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 28 Nov 2010 17:51:25 +0100 (CET)

Author: pulkomandy
Date: 2010-11-28 17:51:25 +0100 (Sun, 28 Nov 2010)
New Revision: 39669
Changeset: http://dev.haiku-os.org/changeset/39669

Modified:
   haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp
   haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h
   haiku/trunk/src/apps/terminal/HistoryBuffer.cpp
   haiku/trunk/src/apps/terminal/TermView.cpp
   haiku/trunk/src/apps/terminal/TerminalLine.h
Log:
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.


Modified: haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp       2010-11-28 
15:57:46 UTC (rev 39668)
+++ haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp       2010-11-28 
16:51:25 UTC (rev 39669)
@@ -240,6 +240,7 @@
                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 @@
 }
 
 
+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 @@
 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;

Modified: haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h
===================================================================
--- haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h 2010-11-28 15:57:46 UTC 
(rev 39668)
+++ haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h 2010-11-28 16:51:25 UTC 
(rev 39669)
@@ -92,6 +92,7 @@
                                                                        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,

Modified: haiku/trunk/src/apps/terminal/HistoryBuffer.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/HistoryBuffer.cpp     2010-11-28 15:57:46 UTC 
(rev 39668)
+++ haiku/trunk/src/apps/terminal/HistoryBuffer.cpp     2010-11-28 16:51:25 UTC 
(rev 39669)
@@ -118,6 +118,7 @@
 
        buffer->length = charCount;
        buffer->softBreak = line->softBreak;
+       buffer->attributes = line->attributes;
 
        return buffer;
 }
@@ -186,6 +187,7 @@
                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);
 }
 

Modified: haiku/trunk/src/apps/terminal/TermView.cpp
===================================================================
--- haiku/trunk/src/apps/terminal/TermView.cpp  2010-11-28 15:57:46 UTC (rev 
39668)
+++ haiku/trunk/src/apps/terminal/TermView.cpp  2010-11-28 16:51:25 UTC (rev 
39669)
@@ -1428,24 +1428,9 @@
                                                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);
                                        }
 

Modified: haiku/trunk/src/apps/terminal/TerminalLine.h
===================================================================
--- haiku/trunk/src/apps/terminal/TerminalLine.h        2010-11-28 15:57:46 UTC 
(rev 39668)
+++ haiku/trunk/src/apps/terminal/TerminalLine.h        2010-11-28 16:51:25 UTC 
(rev 39669)
@@ -7,6 +7,8 @@
 
 #include <SupportDefs.h>
 
+#include "TermConst.h"
+
 #include "UTF8Char.h"
 
 
@@ -19,11 +21,13 @@
 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 @@
        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
        {


Other related posts: