From 429650ab7cf4eaebd470003c734c98c93537984a Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Thu, 14 Apr 2016 16:21:02 -0400 Subject: Get some more of the terminal cleaned up. Now "vi" has partial support (still no functional arrow keys though) --- .../lumina-terminal/TerminalWidget.cpp | 67 ++++++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) (limited to 'desktop-utilities/lumina-terminal/TerminalWidget.cpp') diff --git a/desktop-utilities/lumina-terminal/TerminalWidget.cpp b/desktop-utilities/lumina-terminal/TerminalWidget.cpp index 14f5dc91..6e05531b 100644 --- a/desktop-utilities/lumina-terminal/TerminalWidget.cpp +++ b/desktop-utilities/lumina-terminal/TerminalWidget.cpp @@ -23,11 +23,14 @@ TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent) this->setAcceptRichText(false); this->setOverwriteMode(true); this->setFocusPolicy(Qt::StrongFocus); + this->setWordWrapMode(QTextOption::NoWrap); this->setContextMenuPolicy(Qt::CustomContextMenu); DEFFMT = this->textCursor().charFormat(); //save the default structure for later CFMT = this->textCursor().charFormat(); //current format selCursor = this->textCursor(); //used for keeping track of selections lastCursor = this->textCursor(); + startrow = endrow = -1; + altkeypad = false; QFontDatabase FDB; QStringList fonts = FDB.families(QFontDatabase::Latin); for(int i=0; i'){ altkeypad = false; } + else{ + qDebug() << "Unhandled ANSI Code:" << code; + } + }else if(code.startsWith("[")){ // VT100 ESCAPE CODES //CURSOR MOVEMENT if( code.endsWith("A") ){ //Move Up @@ -165,8 +175,13 @@ void TerminalWidget::applyANSI(QByteArray code){ int mid = code.indexOf(";"); if(mid>1){ int numR, numC; numR = numC = 1; - if(mid >=3){ numR = code.mid(1,mid-1).toInt(); } + if(mid >=2){ numR = code.mid(1,mid-1).toInt(); } if(mid < code.size()-1){ numC = code.mid(mid+1,code.size()-mid-2).toInt(); } + + if(startrow>=0 && endrow>=0){ + if(numR == startrow){ numR = 0;} + else if(numR==endrow){ numR = this->document()->lineCount()-1; } + } qDebug() << "Set Text Position (absolute):" << "Code:" << code << "Row:" << numR << "Col:" << numC; //qDebug() << " - Current Pos:" << this->textCursor().position() << "Line Count:" << this->document()->lineCount(); //if(!this->textCursor().movePosition(QTextCursor::Start, QTextCursor::MoveAnchor,1) ){ qDebug() << "Could not go to start"; } @@ -179,13 +194,22 @@ void TerminalWidget::applyANSI(QByteArray code){ /*this->textCursor().setPosition( this->document()->findBlockByLineNumber(numR).position() ); qDebug() << " - Pos After Row Move:" << this->textCursor().position(); if( !this->textCursor().movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, numC) ){ qDebug() << "Could not go to col:" << numC; }*/ - qDebug() << " - Ending Pos:" << cur.position(); + //qDebug() << " - Ending Pos:" << cur.position(); this->setTextCursor(cur); }else{ //Go to home position this->moveCursor(QTextCursor::Start); } - + + // CURSOR MANAGEMENT + }else if(code.endsWith("r")){ //Tag top/bottom lines as perticular numbers + int mid = code.indexOf(";"); + qDebug() << "New Row Codes:" << code << "midpoint:" << mid; + if(mid>1){ + if(mid >=2){ startrow = code.mid(1,mid-1).toInt(); } + if(mid < code.size()-1){ endrow = code.mid(mid+1,code.size()-mid-2).toInt(); } + } + qDebug() << "New Row Codes:" << startrow << endrow; // DISPLAY CLEAR CODES }else if(code.endsWith("J")){ //ED - Erase Display int num = 0; @@ -235,10 +259,10 @@ void TerminalWidget::applyANSI(QByteArray code){ } //SCROLL MOVEMENT CODES - }else if(code.endsWith("S")){ // SU - Scroll Up - qDebug() << "Scroll Up:" << code; - }else if(code.endsWith("T")){ // SD - Scroll Down - qDebug() << "Scroll Down:" << code; + //}else if(code.endsWith("S")){ // SU - Scroll Up + //qDebug() << "Scroll Up:" << code; + //}else if(code.endsWith("T")){ // SD - Scroll Down + //qDebug() << "Scroll Down:" << code; // GRAPHICS RENDERING }else if(code.endsWith("m")){ @@ -258,9 +282,9 @@ void TerminalWidget::applyANSI(QByteArray code){ // GRAPHICS MODES - }else if(code.endsWith("h")){ + //}else if(code.endsWith("h")){ - }else if(code.endsWith("l")){ + //}else if(code.endsWith("l")){ }else{ qDebug() << "Unhandled Control Code:" << code; @@ -355,16 +379,20 @@ void TerminalWidget::sendKeyPress(int key){ ba.append("\x08"); break; case Qt::Key_Left: - ba.append("\x1b[D"); + if(altkeypad){ ba.append("^[D"); } + else{ ba.append("\x1b[D"); } break; case Qt::Key_Right: - ba.append("\x1b[C"); + if(altkeypad){ ba.append("^[C"); } + else{ ba.append("\x1b[C"); } break; case Qt::Key_Up: - ba.append("\x1b[A"); + if(altkeypad){ ba.append("^[A"); } + else{ ba.append("\x1b[A"); } break; case Qt::Key_Down: - ba.append("\x1b[B"); + if(altkeypad){ ba.append("^[B"); } + else{ ba.append("\x1b[B"); } break; case Qt::Key_Home: ba.append("\x1b[H"); @@ -373,7 +401,7 @@ void TerminalWidget::sendKeyPress(int key){ ba.append("\x1b[F"); break; } - //qDebug() << "Forward Input:" << ba; + qDebug() << "Forward Input:" << ba; if(!ba.isEmpty()){ PROC->writeTTY(ba); } } @@ -386,7 +414,8 @@ void TerminalWidget::UpdateText(){ if(!PROC->isOpen()){ return; } applyData(PROC->readTTY()); //adjust the scrollbar as needed - this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); + this->ensureCursorVisible(); + //this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); } void TerminalWidget::ShellClosed(){ -- cgit