@@ -50,12 +50,17 @@ void QVTerminal::appendData(const QByteArray &data)
50
50
51
51
setUpdatesEnabled (false );
52
52
QByteArray::const_iterator it = data.cbegin ();
53
+
54
+ qDebug () << " appendData=" +data;
55
+
53
56
while (it != data.cend ()) {
54
57
QChar c = *it;
55
58
switch (_state) {
56
59
case QVTerminal::Text:
57
60
switch (c.unicode ()) {
58
61
case ' \033 ' :
62
+ // \033即\x1B即ASCII 27,ESC
63
+ // 匹配ESC[,即CSI ,Control Sequence Introducer
59
64
appendString (text);
60
65
text.clear ();
61
66
_state = QVTerminal::Escape;
@@ -113,6 +118,9 @@ void QVTerminal::appendData(const QByteArray &data)
113
118
} else {
114
119
_state = QVTerminal::Text;
115
120
}
121
+ }else if (c==' J' ) {
122
+ reduceString (-1 );
123
+ _state = QVTerminal::Text;
116
124
} else {
117
125
formatChar (c);
118
126
_state = QVTerminal::Text;
@@ -127,6 +135,7 @@ void QVTerminal::appendData(const QByteArray &data)
127
135
it++;
128
136
}
129
137
appendString (text);
138
+
130
139
verticalScrollBar ()->setRange (0 , _ch * (_layout->lineCount () + 1 ) - viewport ()->size ().height ());
131
140
verticalScrollBar ()->setValue (verticalScrollBar ()->maximum ());
132
141
setUpdatesEnabled (true );
@@ -201,13 +210,24 @@ void QVTerminal::read()
201
210
202
211
void QVTerminal::appendString (QString str)
203
212
{
213
+ // qDebug() << "appendString="+str;
204
214
foreach (QChar c, str) {
205
215
QVTChar termChar (c, _curentFormat);
206
216
_layout->lineAt (_cursorPos.y ()).append (termChar, _cursorPos.x ());
207
217
_cursorPos.setX (_cursorPos.x () + 1 );
208
218
}
209
219
}
210
220
221
+ void QVTerminal::reduceString (int mode)
222
+ {
223
+ if (mode>0 )
224
+ _layout->lineAt (_cursorPos.y ()).reduce (_cursorPos.x ()+1 );
225
+ else {
226
+ _layout->lineAt (_cursorPos.y ()).reduce (_cursorPos.x ());
227
+ // _cursorPos.setX(_cursorPos.x() -1);
228
+ }
229
+ }
230
+
211
231
void QVTerminal::toggleCursor ()
212
232
{
213
233
_cvisible = !_cvisible;
@@ -299,6 +319,20 @@ void QVTerminal::keyPressEvent(QKeyEvent *event)
299
319
case Qt::Key_Backspace:
300
320
data.append (' \b ' );
301
321
break ;
322
+ // ref.PC-Style Function Keys
323
+ // https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
324
+ case Qt::Key_Delete:
325
+ data.append (" \033 [3~" );
326
+ break ;
327
+ case Qt::Key_Insert:
328
+ data.append (" \033 [2~" );
329
+ break ;
330
+ case Qt::Key_PageUp:
331
+ data.append (" \033 [5~" );
332
+ break ;
333
+ case Qt::Key_PageDown:
334
+ data.append (" \033 [6~" );
335
+ break ;
302
336
case Qt::Key_Return:
303
337
data.append (' \n ' );
304
338
break ;
0 commit comments