Skip to content

Does not manage Cursor Handling instructions #2

@Telectroboy

Description

@Telectroboy

Hey guys,
I'm trying to add the cursor handling function to this repo.

Here a part where I've succesfully modified the cursor display in qvterminal.cpp :

void QVTerminal::appendData(const QByteArray &data)
{
setUpdatesEnabled(false);
QByteArray::const_iterator it = data.cbegin();
while (it != data.cend())
{
QChar c = it;
switch (_state)
{
case QVTerminal::Text:
qDebug()<<"State:Text"<<c;
if (c == 0x1B) //caractère ESC
{
appendString(text2);
text2.clear();
_state = QVTerminal::Escape;
}
else if (c == '\n' || c == '\xd') //Touche ENTREE passe à la ligne
{
qDebug()<<"Entrée"<<c;
appendString(text2);
text2.clear();
_layout->appendLine();
_cursorPos.setX(0);
_cursorPos.setY(_cursorPos.y() + 1);
}
else if (c.isPrint()) //Si caractère affichable classique
{
qDebug()<<_cursorPos.x()<<_cursorPos.y();
text2.append(c);
}
break;
case QVTerminal::Escape:
_formatValue = 0;
qDebug()<<"State:Escape"<<c;
if (c == 0x5B) // lorsque data = [ soit 5B
{
ArgValue1 = 0;
ArgValue2 = 0;
qDebug()<<ArgValue1<<ArgValue2;
multiplicateur = 10;
_state = QVTerminal::Argument1;
}
else if (c == '(')
{
_state = QVTerminal::ResetFont;
}
break;
//1B 5B 30 31 3B 31 34 48 = ESC[01;14H = position du curseur => _cursorPos.setX(0); _cursorPos.setY(0);
//http://domoticx.com/terminal-codes-ansivt100/
case QVTerminal::Argument1:
qDebug()<<"passe dans Argument1 c= "<<c;
if (c >= '0' && c <= '9')
{
ArgValue1 = ArgValue1 + (c.digitValue()
multiplicateur);
multiplicateur = 1;
}
else if (c == ';')
{
_state = QVTerminal::Argument2;
multiplicateur = 10;
}
else if (c == 'H')
{
_cursorPos.setY(ArgValue1);
_cursorPos.setX(ArgValue2);
_state = QVTerminal::Text;
}
else if (c == 'm')
_state = QVTerminal::Format;
else
_state = QVTerminal::Text;
break;
case QVTerminal::Argument2:
qDebug()<<"passe dans Argument2 c= "<<c;
if (c >= '0' && c <= '9')
{
ArgValue2 = ArgValue2 + (c.digitValue() * multiplicateur);
multiplicateur = 1;
}
else if (c == 'H')
{
_cursorPos.setY(ArgValue1);
_cursorPos.setX(ArgValue2);
_state = QVTerminal::Text;
}
else if (c == 'm')
_state = QVTerminal::Format;
else
_state = QVTerminal::Text;
break;
case QVTerminal::Format:
qDebug()<<"entre dans State:Format"<<c;
if (c >= '0' && c <= '9')
{
qDebug()<<"c entre 0 et 9";
_formatValue = _formatValue * 10 + (c.cell() - '0');
}
else
{
if ( c == 'm') //si la seconde lettre = m alors passe en mode attributs du texte
{
qDebug()<<"c = m";
if (_formatValue == 0) // reset format
{
_curentFormat = _format;
}
else if (_formatValue == 4) // underline
{
_curentFormat.font().setUnderline(true);
}
else if (_formatValue == 7) // reverse
{
QColor foreground = _curentFormat.foreground();
_curentFormat.setForeground(_curentFormat.background());
_curentFormat.setBackground(foreground);
}
else if (_formatValue / 10 == 3) // foreground
{
_curentFormat.setForeground(vt100color((_formatValue % 10) + '0'));
}
else if (_formatValue / 10 == 4) // background
{
_curentFormat.setBackground(vt100color((_formatValue % 10) + '0'));
}
if (c == ';')
{
_formatValue = 0;
_state = QVTerminal::Format;
}
else
{
_state = QVTerminal::Text;
}
}
else
{
_state = QVTerminal::Text;
}
}
break;
case QVTerminal::ResetFont:
_curentFormat = _format;
_state = QVTerminal::Text;
break;
}
it++;
}
appendString(text2);
verticalScrollBar()->setRange(0, _ch * (_layout->lineCount() + 1) - viewport()->size().height() + 6);
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
setUpdatesEnabled(true);
update();
}

It works with instructions like [01;14H (a crash after the next string if nothing in the line.
But the datas aren't displayed at the good place.

I know that I have to modify void QVTerminal::paintEvent(QPaintEvent *paintEvent) but I'm lost. It never work.
Can you help me?

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions