Skip to content

Commit

Permalink
[fingerterm] Ensure that blank insertion is done with the proper back…
Browse files Browse the repository at this point in the history
…ground and foreground color.
  • Loading branch information
dcaliste committed May 7, 2021
1 parent 08a5efc commit 2563831
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
34 changes: 20 additions & 14 deletions terminal.cpp
Expand Up @@ -43,11 +43,6 @@ Terminal::Terminal(QObject *parent) :
iTermSize(0,0), iEmitCursorChangeSignal(true),
iShowCursor(true), iUseAltScreenBuffer(false), iAppCursorKeys(false)
{
zeroChar.c = ' ';
zeroChar.bgColor = defaultBgColor;
zeroChar.fgColor = defaultFgColor;
zeroChar.attrib = 0;

escape = -1;

iTermAttribs.currentFgColor = defaultFgColor;
Expand All @@ -73,6 +68,18 @@ void Terminal::setPtyIFace(PtyIFace *pty)
}
}

TermChar Terminal::zeroChar() const
{
TermChar ch;

ch.c = ' ';
ch.bgColor = iTermAttribs.currentBgColor;
ch.fgColor = iTermAttribs.currentFgColor;
ch.attrib = iTermAttribs.currentAttrib;

return ch;
}

void Terminal::setCursorPos(QPoint pos)
{
if( iTermAttribs.cursorPos != pos ) {
Expand Down Expand Up @@ -465,10 +472,10 @@ void Terminal::insertAtCursor(QChar c, bool overwriteMode, bool advanceCursor)
}

while(currentLine().size() < cursorPos().x() )
currentLine().append(zeroChar);
currentLine().append(zeroChar());

if(!overwriteMode)
currentLine().insert(cursorPos().x()-1,zeroChar);
currentLine().insert(cursorPos().x()-1,zeroChar());

currentLine()[cursorPos().x()-1].c = c;
currentLine()[cursorPos().x()-1].fgColor = iTermAttribs.currentFgColor;
Expand Down Expand Up @@ -499,9 +506,9 @@ void Terminal::clearAt(QPoint pos)
while(buffer().size() < pos.y())
buffer().append(QList<TermChar>());
while(buffer()[pos.y()-1].size() < pos.x() )
buffer()[pos.y()-1].append(zeroChar);
buffer()[pos.y()-1].append(zeroChar());

buffer()[pos.y()-1][pos.x()-1] = zeroChar;
buffer()[pos.y()-1][pos.x()-1] = zeroChar();
}

void Terminal::eraseLineAtCursor(int from, int to)
Expand All @@ -521,9 +528,8 @@ void Terminal::eraseLineAtCursor(int from, int to)
if(from>to)
return;

for(int i=from; i<=to; i++) {
currentLine()[i] = zeroChar;
}
for(int i=from; i<=to; i++)
currentLine()[i] = zeroChar();
}

void Terminal::clearAll(bool wholeBuffer)
Expand Down Expand Up @@ -750,7 +756,7 @@ void Terminal::ansiSequence(const QString& seq)
if(params.at(0)==0)
params[0] = 1;
for(int i=1; i<=params.at(0); i++)
insertAtCursor(zeroChar.c, false, false);
insertAtCursor(' ', false, false);
break;

case 'S': // scroll up n lines
Expand Down Expand Up @@ -1057,7 +1063,7 @@ void Terminal::escControlChar(const QString& seq)
for (int i = 0; i < rows(); i++) {
QList<TermChar> line;
for(int j = 0; j < columns(); j++) {
TermChar c = zeroChar;
TermChar c = zeroChar();
c.c = 'E';
line.append(c);
}
Expand Down
2 changes: 1 addition & 1 deletion terminal.h
Expand Up @@ -104,7 +104,7 @@ class Terminal : public QObject
int rows();
int columns();

TermChar zeroChar;
TermChar zeroChar() const;

signals:
void cursorPosChanged(QPoint newPos);
Expand Down
9 changes: 4 additions & 5 deletions textrender.cpp
Expand Up @@ -170,9 +170,8 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
const int leftmargin = 2;
int cutAfter = property("cutAfter").toInt() + iFontDescent;

TermChar tmp = sTerm->zeroChar;
TermChar nextAttrib = sTerm->zeroChar;
TermChar currAttrib = sTerm->zeroChar;
TermChar nextAttrib = sTerm->zeroChar();
TermChar currAttrib = sTerm->zeroChar();
int currentX = leftmargin;
for(int i=from; i<to; i++) {
y += iFontHeight;
Expand All @@ -188,7 +187,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
currentX = leftmargin;
int fragWidth = 0;
for(int j=0; j<xcount; j++) {
tmp = buffer[i][j];
TermChar tmp = buffer[i][j];
fragWidth += iFontWidth;
if (j==0) {
currAttrib = tmp;
Expand All @@ -215,7 +214,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
QString line;
currentX = leftmargin;
for (int j=0; j<xcount; j++) {
tmp = buffer[i][j];
TermChar tmp = buffer[i][j];
line += tmp.c;
if (j==0) {
currAttrib = tmp;
Expand Down

0 comments on commit 2563831

Please sign in to comment.