当前位置:网站首页>QT VT100 parser
QT VT100 parser
2022-07-05 10:09:00 【cppphp】
Recently, with Qt Developing a serial port program requires that VT100 To analyze , The current project has been accepted , For the sake of remembering VT100 The decoding part is sorted out , It can also provide a reference for those who need it .
One 、VT100 Control code VT100 Is a terminal type definition ,VT100 The control code is the code used to expand the display on the terminal . For example, any coordinate on the terminal displays characters in different colors . All controllers are '\033'( octal ) start . VT100 The control code is as follows : \033[0m Cancel all previous properties \033[1m High brightness \033[4m Underline \033[5m flashing \033[7m Reflexion \033[8m Blanking \033[30m -- \033[37m Set the foreground \033[40m -- \033[47m Set background color \033[nA The cursor moves up n That's ok \033[nB The cursor moves down n That's ok \033[nC The cursor moves right n That's ok \033[nD The cursor moves left n That's ok \033[y;xH Set cursor position \033[2J Clear the screen \033[K Clear the contents from the cursor to the end of the line \033[s Save cursor position \033[u Restore cursor position \033[?25l hide cursor \033[?25h Show cursor Background color range :40----49 40: black 41: Crimson 42: green 43: yellow 44: Blue 45: violet 46: Dark green 47: white Word foreground color range :30----39 30: black 31: red 32: green 33: yellow 34: Blue 35: violet 36: Dark green 37: white
Two 、 Program
// VT100 analysis
QString comBySocket::backDataConvent(QString read)
{
const QTextCursor::MoveOperation moCursor[] = {QTextCursor::Up,QTextCursor::Down,QTextCursor::Right,QTextCursor::Left};
QString subRead = read;
bool hasTail = false;
int index = subRead.indexOf("\033[");
int vtLen = 1;
int x,y;
int n;
QTextCursor tc;
tc = ui.textEditIn->textCursor();
while(index>-1 && hasTail==false){
QString tem;
if(index>=0){
ui.textEditIn->insertPlainText(subRead.left(index));
ui.textEditIn->moveCursor(QTextCursor::EndOfLine);
subRead = subRead.right(subRead.length()-index-2);
}
if(subRead.length()<1){
hasTail = true;
break;
}
switch(subRead[0].toAscii()){
case 'K':// Clear the contents from the cursor to the end of the line
tc.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
tc.removeSelectedText();
vtLen = 1;
break;
case 's':// Save cursor position
vtLen = 1;
break;
case'a':// Restore cursor position
vtLen = 1;
break;
case'?':
if(subRead.length()<4)
hasTail = true;
else{
tem = subRead.mid(1,3);
if(tem=="25l"){// hide cursor
ui.textEditIn->setCursor(Qt::BlankCursor);
}else if(tem=="25h"){// Show cursor
ui.textEditIn->setCursor(Qt::ArrowCursor);
}
vtLen = 4;
}
break;
default:
n=1;
while(subRead.length()>n && subRead[n]>='0' && subRead[n]<='9'){
n++;
}
if(n>=subRead.length()){
hasTail = true;
}else{
y = subRead.mid(0,n).toInt();
switch(subRead[n].toAscii()){
case 'm':
switch(y){
case 0:// Turn off all properties
ui.textEditIn->setFontUnderline(false);
ui.textEditIn->setTextColor(Qt::black);
ui.textEditIn->setTextBackgroundColor(Qt::white);
ui.textEditIn->setCursor(Qt::ArrowCursor);
vtLen = 2;
break;
case 1:// Set to highlight
ui.textEditIn->setTextBackgroundColor(textBackColor.lighter(150));
vtLen = 2;
break;
case 4:// Underline
ui.textEditIn->setFontUnderline(true);
vtLen = 2;
break;
case 5:// flashing
//tc.set
vtLen = 2;
break;
case 7:// Reflexion
ui.textEditIn->setTextColor(textBackColor);
ui.textEditIn->setTextBackgroundColor(textColor);
vtLen = 2;
break;
case 8:// Blanking
vtLen = 2;
break;
case 30:// Set the foreground black
case 31:// Set the foreground Red
case 32:// Set the foreground green
case 33:// Set the foreground yellow
case 34:// Set the foreground Blue
case 35:// Set the foreground violet
case 36:// Set the foreground Cyan
case 37:// Set the foreground white
case 38:// Set the foreground white
case 39:// Set the foreground white
case 40:// Set background color black
case 41:// Set background color Red
case 42:// Set background color green
case 43:// Set background color yellow
case 44:// Set background color Blue
case 45:// Set background color violet
case 46:// Set background color Cyan
case 47:// Set background color white
case 48:// Set background color white
case 49:// Set background color white
setForntColor(y);
vtLen = 3;
break;
}
break;
case 'J':
if(y==2 && n==1){// Clear the screen
inClear();
vtLen = 2;
}
break;
case 'A':// The cursor moves up n That's ok
case 'B':// The cursor moves down n That's ok
case 'C':// The cursor moves right n That's ok
case 'D':// The cursor moves left n That's ok
tc.movePosition(moCursor[subRead[0].toAscii()-'A'],QTextCursor::MoveAnchor,y);
vtLen = n+1;
break;
case ';':
x = n++;
while(subRead.length()>n && subRead[n]>='0' && subRead[n]<='9'){
n++;
}
if(n>=subRead.length()){
hasTail = true;
}else{
//QString tem = subRead.mid(x+1,n-x-1);
x = subRead.mid(x+1,n-x-1).toInt();
vtLen = n+1;
//QMessageBox::information(NULL,QString::number(y, 10)+","+QString::number(x, 10)+"("+tem+")",subRead, QMessageBox::Ok);
if(subRead[n]=='H'){// Set cursor position
ui.textEditIn->moveCursor(QTextCursor::Start);
tc.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,y);
tc.movePosition(QTextCursor::Right,QTextCursor::MoveAnchor,x);
}else if(subRead[n]=='m'){
setForntColor(x);
setForntColor(y);
}
}
break;
}
}
}
if(hasTail) break;
int strlen = subRead.length()-vtLen;
if(strlen>=0)
subRead = subRead.right(strlen);
index = subRead.indexOf("\033[");
}
if(hasTail)
return "\033["+subRead;
else{
if(subRead.length()>0){
if(subRead[subRead.length()-1] == '\033'){
ui.textEditIn->insertPlainText(subRead.left(subRead.length()-1));
return "\033";
}
ui.textEditIn->insertPlainText(subRead);
//ui.textEditIn->append(subRead);
}
}
ui.textEditIn->moveCursor(QTextCursor::End);
return "";
}
边栏推荐
- Implementation of smart home project
- 【OpenCV 例程200篇】219. 添加数字水印(盲水印)
- 为什么不建议你用 MongoDB 这类产品替代时序数据库?
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- MySQL字符类型学习笔记
- H. 265 introduction to coding principles
- Tdengine can read and write through dataX, a data synchronization tool
- The comparison of every() and some() in JS uses a power storage plan
- 7 月 2 日邀你来TD Hero 线上发布会
- Oracle combines multiple rows of data into one row of data
猜你喜欢
Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
Tdengine connector goes online Google Data Studio app store
美图炒币半年亏了3个亿,华为被曝在俄罗斯扩招,AlphaGo的同类又刷爆一种棋,今日更多大新闻在此...
卷起來,突破35歲焦慮,動畫演示CPU記錄函數調用過程
Tongweb set gzip
Is it really reliable for AI to make complex decisions for enterprises? Participate in the live broadcast, Dr. Stanford to share his choice | qubit · viewpoint
Wechat applet - simple diet recommendation (4)
随机推荐
Online chain offline integrated chain store e-commerce solution
搞数据库是不是越老越吃香?
为什么不建议你用 MongoDB 这类产品替代时序数据库?
能源势动:电力行业的碳中和该如何实现?
百度智能小程序巡檢調度方案演進之路
Officially launched! Tdengine plug-in enters the official website of grafana
Unity粒子特效系列-毒液喷射预制体做好了,unitypackage包直接用 - 上
一种用于干式脑电图的高密度256通道电极帽
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
Kotlin compose multiple item scrolling
Oracle combines multiple rows of data into one row of data
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
On July 2, I invite you to TD Hero online press conference
一文读懂TDengine的窗口查询功能
如何正确的评测视频画质
The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
天龙八部TLBB系列 - 关于包裹掉落的物品
Fluent development: setting method of left and right alignment of child controls in row
The writing speed is increased by dozens of times, and the application of tdengine in tostar intelligent factory solution
从“化学家”到开发者,从甲骨文到TDengine,我人生的两次重要抉择