From 2053dc33e0d76b51d477f3c4c50278c0258b7f00 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 11 Mar 2016 15:04:24 -0500 Subject: Get the terminal resizing routine working, and also get the up/down arrows functional (mostly). --- .../lumina-terminal/TerminalWidget.cpp | 16 ++++++++ desktop-utilities/lumina-terminal/TerminalWidget.h | 2 + desktop-utilities/lumina-terminal/TtyProcess.cpp | 44 ++++++++++++++++------ desktop-utilities/lumina-terminal/TtyProcess.h | 3 ++ 4 files changed, 54 insertions(+), 11 deletions(-) (limited to 'desktop-utilities/lumina-terminal') diff --git a/desktop-utilities/lumina-terminal/TerminalWidget.cpp b/desktop-utilities/lumina-terminal/TerminalWidget.cpp index 96b86bda..1756d0b1 100644 --- a/desktop-utilities/lumina-terminal/TerminalWidget.cpp +++ b/desktop-utilities/lumina-terminal/TerminalWidget.cpp @@ -49,6 +49,11 @@ void TerminalWidget::UpdateText(){ QByteArray buffer = PROC->readTTY(); QString text = QString(buffer); text.replace("\r\n","\n"); + //Special Cursor handling + while(text.startsWith("\b")){ + this->textCursor().deletePreviousChar(); + text = text.remove(0,1); + } this->insertPlainText(text); //adjust the scrollbar as needed this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum()); @@ -85,3 +90,14 @@ void TerminalWidget::mouseDoubleClickEvent(QMouseEvent *ev){ void TerminalWidget::contextMenuEvent(QContextMenuEvent *ev){ Q_UNUSED(ev); } + +void TerminalWidget::resizeEvent(QResizeEvent *ev){ + if(!PROC->isOpen()){ return; } + QSize pix = ev->size(); //pixels + QSize chars; + chars.setWidth( pix.width()/this->fontMetrics().width("W") ); + chars.setHeight( pix.height()/this->fontMetrics().lineSpacing() ); + + PROC->setTerminalSize(chars,pix); + QTextEdit::resizeEvent(ev); +} diff --git a/desktop-utilities/lumina-terminal/TerminalWidget.h b/desktop-utilities/lumina-terminal/TerminalWidget.h index 59d097d4..49b255ff 100644 --- a/desktop-utilities/lumina-terminal/TerminalWidget.h +++ b/desktop-utilities/lumina-terminal/TerminalWidget.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -40,6 +41,7 @@ protected: void mousePressEvent(QMouseEvent *ev); void mouseDoubleClickEvent(QMouseEvent *ev); void contextMenuEvent(QContextMenuEvent *ev); + void resizeEvent(QResizeEvent *ev); }; #endif diff --git a/desktop-utilities/lumina-terminal/TtyProcess.cpp b/desktop-utilities/lumina-terminal/TtyProcess.cpp index 1941ecd9..15094f64 100644 --- a/desktop-utilities/lumina-terminal/TtyProcess.cpp +++ b/desktop-utilities/lumina-terminal/TtyProcess.cpp @@ -68,21 +68,20 @@ void TTYProcess::writeTTY(QByteArray output){ } void TTYProcess::writeQtKey(int key){ - //Note that a shell does *not* take ANSI QByteArray ba; //Check for special keys switch(key){ case Qt::Key_Backspace: - //ba.append("^H/x1b[8p"); + ba.append("\x1b[D\x1b[K"); break; case Qt::Key_Left: case Qt::Key_Right: break; case Qt::Key_Up: - //ba.append("\x1b[(224;72)p"); + ba.append("\x1b[A"); break; case Qt::Key_Down: - //ba.append("\x1b[(224;80)p"); + ba.append("\x1b[B"); break; } @@ -92,11 +91,13 @@ void TTYProcess::writeQtKey(int key){ QByteArray TTYProcess::readTTY(){ QByteArray BA; + qDebug() << "Read TTY"; if(sn==0){ return BA; } //not setup yet char buffer[64]; ssize_t rtot = read(sn->socket(),&buffer,64); buffer[rtot]='\0'; BA = QByteArray(buffer, rtot); + qDebug() << " - Got Data:" << BA; if(!fragBA.isEmpty()){ //Have a leftover fragment, include this too BA = BA.prepend(fragBA); @@ -114,6 +115,21 @@ QByteArray TTYProcess::readTTY(){ } } +void TTYProcess::setTerminalSize(QSize chars, QSize pixels){ + if(ttyfd==0){ return; } + + struct winsize c_sz; + c_sz.ws_row = chars.height(); + c_sz.ws_col = chars.width(); + c_sz.ws_xpixel = pixels.width(); + c_sz.ws_ypixel = pixels.height(); + if( ioctl(ttyfd, TIOCSWINSZ, &ws) ){ + qDebug() << "Error settings terminal size"; + }else{ + qDebug() <<"Set Terminal Size:" << pixels << chars; + } +} + bool TTYProcess::isOpen(){ return (ttyfd!=0); } @@ -134,12 +150,19 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){ index = raw.indexOf("\x1B]"); } - // COLOR CODES + // GENERIC ANSI CODES index = raw.indexOf("\x1B["); while(index>=0){ - int end = raw.indexOf("m",index); - if(end<0){ return raw; } //incomplete raw array - raw = raw.remove(index, end-index+1); + //CURSOR MOVEMENT + int end = 0; + for(int i=1; ikey() ) QByteArray readTTY(); + //Setup the terminal size (characters and pixels) + void setTerminalSize(QSize chars, QSize pixels); + //Status update checks bool isOpen(); -- cgit