Skip to content

Commit

Permalink
[fingerterm] Kill line with current style. Contributes to JB#53070
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed May 7, 2021
1 parent eaf845b commit a03f876
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
36 changes: 25 additions & 11 deletions terminal.cpp
Expand Up @@ -118,7 +118,7 @@ bool Terminal::showCursor()
return iShowCursor;
}

QList<QList<TermChar> >& Terminal::buffer()
QList<TermLine>& Terminal::buffer()
{
if(iUseAltScreenBuffer)
return iAltBuffer;
Expand Down Expand Up @@ -475,7 +475,7 @@ void Terminal::insertAtCursor(QChar c, bool overwriteMode, bool advanceCursor)
currentLine().append(zeroChar());

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

currentLine()[cursorPos().x()-1].c = c;
currentLine()[cursorPos().x()-1].fgColor = iTermAttribs.currentFgColor;
Expand All @@ -490,7 +490,7 @@ void Terminal::insertAtCursor(QChar c, bool overwriteMode, bool advanceCursor)
void Terminal::deleteAt(QPoint pos)
{
clearAt(pos);
buffer()[pos.y()-1].removeAt(pos.x()-1);
buffer()[pos.y()-1].l.removeAt(pos.x()-1);
}

void Terminal::clearAt(QPoint pos)
Expand All @@ -504,7 +504,7 @@ void Terminal::clearAt(QPoint pos)

// just in case...
while(buffer().size() < pos.y())
buffer().append(QList<TermChar>());
buffer().append(TermLine());
while(buffer()[pos.y()-1].size() < pos.x() )
buffer()[pos.y()-1].append(zeroChar());

Expand All @@ -525,6 +525,10 @@ void Terminal::eraseLineAtCursor(int from, int to)
to=currentLine().size();
to--;

currentLine().fgColor = iTermAttribs.currentFgColor;
currentLine().bgColor = iTermAttribs.currentBgColor;
currentLine().attrib = iTermAttribs.currentAttrib;

if(from>to)
return;

Expand Down Expand Up @@ -774,6 +778,16 @@ void Terminal::ansiSequence(const QString& seq)
scrollBack(params.at(0));
break;

case 'X': // erase n characters
if (params.count() == 1) {
for (int i = 0; i < params[0]; i++)
insertAtCursor(' ', true, true);
setCursorPos(QPoint(cursorPos().x() - params[0], cursorPos().y()));
} else {
unhandled = true;
}
break;

case 'c': // vt100 identification
if(params.count()==0)
params.append(0);
Expand Down Expand Up @@ -1061,7 +1075,7 @@ void Terminal::escControlChar(const QString& seq)
if( seq.at(0) == '#' && seq.at(1)=='8' ) { // test mode, fill screen with 'E'
clearAll(true);
for (int i = 0; i < rows(); i++) {
QList<TermChar> line;
TermLine line;
for(int j = 0; j < columns(); j++) {
TermChar c = zeroChar();
c.c = 'E';
Expand Down Expand Up @@ -1115,10 +1129,10 @@ void Terminal::escControlChar(const QString& seq)
}
}

QList<TermChar>& Terminal::currentLine()
TermLine& Terminal::currentLine()
{
while(buffer().size() <= cursorPos().y()-1)
buffer().append(QList<TermChar>());
buffer().append(TermLine());

if( cursorPos().y() >= 1 &&
cursorPos().y() <= buffer().size() )
Expand Down Expand Up @@ -1176,9 +1190,9 @@ void Terminal::scrollBack(int lines, int insertAt)
if(iBackBuffer.size()>0 && useBackbuffer)
buffer().insert(insertAt, iBackBuffer.takeLast());
else
buffer().insert(insertAt, QList<TermChar>());
buffer().insert(insertAt, TermLine());
} else {
buffer().insert(insertAt, QList<TermChar>());
buffer().insert(insertAt, TermLine());
}

int rm = iMarginBottom;
Expand All @@ -1204,10 +1218,10 @@ void Terminal::scrollFwd(int lines, int removeAt)
removeAt--;

while(buffer().size() < iMarginBottom)
buffer().append(QList<TermChar>());
buffer().append(TermLine());

while(lines>0) {
buffer().insert(iMarginBottom, QList<TermChar>());
buffer().insert(iMarginBottom, TermLine());

if(!iUseAltScreenBuffer)
iBackBuffer.append( buffer().takeAt(removeAt) );
Expand Down
40 changes: 34 additions & 6 deletions terminal.h
Expand Up @@ -50,6 +50,34 @@ struct TermAttribs {
int currentAttrib;
};

struct TermLine {
QList<TermChar> l;
int fgColor;
int bgColor;
int attrib;

TermLine()
: fgColor(0), bgColor(0), attrib(0)
{
}
TermChar& operator[](int i)
{
return l[i];
}
int size() const
{
return l.size();
}
void clear()
{
return l.clear();
}
void append(const TermChar &c)
{
l.append(c);
}
};

class Terminal : public QObject
{
Q_OBJECT
Expand All @@ -76,10 +104,10 @@ class Terminal : public QObject
QSize termSize() { return iTermSize; }
void setTermSize(QSize size);

QList<QList<TermChar> >& buffer();
QList<QList<TermChar> >& backBuffer() { return iBackBuffer; }
QList<TermLine>& buffer();
QList<TermLine>& backBuffer() { return iBackBuffer; }

QList<TermChar>& currentLine();
TermLine& currentLine();

Q_INVOKABLE void keyPress(int key, int modifiers, const QString& text="");
Q_INVOKABLE const QStringList printableLinesFromCursor(int lines);
Expand Down Expand Up @@ -138,9 +166,9 @@ class Terminal : public QObject
QQuickView* iWindow;
Util* iUtil;

QList<QList<TermChar> > iBuffer;
QList<QList<TermChar> > iAltBuffer;
QList<QList<TermChar> > iBackBuffer;
QList<TermLine> iBuffer;
QList<TermLine> iAltBuffer;
QList<TermLine> iBackBuffer;
QList<QList<int> > iTabStops;

QSize iTermSize;
Expand Down
13 changes: 9 additions & 4 deletions textrender.cpp
Expand Up @@ -165,7 +165,7 @@ void TextRender::paint(QPainter* painter)
painter->restore();
}

void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buffer, int from, int to, int &y)
void TextRender::paintFromBuffer(QPainter* painter, QList<TermLine>& buffer, int from, int to, int &y)
{
const int leftmargin = 2;
int cutAfter = property("cutAfter").toInt() + iFontDescent;
Expand All @@ -181,7 +181,7 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
else
painter->setOpacity(1.0);

int xcount = qMin(buffer.at(i).count(), sTerm->columns());
int xcount = qMin(buffer.at(i).size(), sTerm->columns());

// background for the current line
currentX = leftmargin;
Expand Down Expand Up @@ -209,8 +209,13 @@ void TextRender::paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buf
currAttrib.fgColor = nextAttrib.fgColor;
}
}
if (currentX < sTerm->columns() * iFontWidth)
drawBgFragment(painter, currentX, y-iFontHeight+iFontDescent, sTerm->columns() * iFontWidth - currentX, currAttrib);
if (currentX < sTerm->columns() * iFontWidth) {
TermChar eol;
eol.fgColor = buffer[i].fgColor;
eol.bgColor = buffer[i].bgColor;
eol.attrib = buffer[i].attrib;
drawBgFragment(painter, currentX, y-iFontHeight+iFontDescent, sTerm->columns() * iFontWidth - currentX, eol);
}

// text for the current line
QString line;
Expand Down
2 changes: 1 addition & 1 deletion textrender.h
Expand Up @@ -79,7 +79,7 @@ private slots:

enum PanGesture { PanNone, PanLeft, PanRight, PanUp, PanDown };

void paintFromBuffer(QPainter* painter, QList<QList<TermChar> >& buffer, int from, int to, int &y);
void paintFromBuffer(QPainter* painter, QList<TermLine>& buffer, int from, int to, int &y);
void drawBgFragment(QPainter* painter, int x, int y, int width, TermChar style);
void drawTextFragment(QPainter* painter, int x, int y, QString text, TermChar style);
QPoint charsToPixels(QPoint pos);
Expand Down

0 comments on commit a03f876

Please sign in to comment.