aboutsummaryrefslogtreecommitdiff
path: root/desktop-utilities/lumina-terminal
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2016-03-11 15:04:24 -0500
committerKen Moore <moorekou@gmail.com>2016-03-11 15:04:24 -0500
commit2053dc33e0d76b51d477f3c4c50278c0258b7f00 (patch)
tree3cb4308b85cd302280b7e04dbb506fbcea2cee08 /desktop-utilities/lumina-terminal
parentFix up the detection of sloppy URL's (www.<something>) - treat them as http U... (diff)
downloadlumina-2053dc33e0d76b51d477f3c4c50278c0258b7f00.tar.gz
lumina-2053dc33e0d76b51d477f3c4c50278c0258b7f00.tar.bz2
lumina-2053dc33e0d76b51d477f3c4c50278c0258b7f00.zip
Get the terminal resizing routine working, and also get the up/down arrows functional (mostly).
Diffstat (limited to 'desktop-utilities/lumina-terminal')
-rw-r--r--desktop-utilities/lumina-terminal/TerminalWidget.cpp16
-rw-r--r--desktop-utilities/lumina-terminal/TerminalWidget.h2
-rw-r--r--desktop-utilities/lumina-terminal/TtyProcess.cpp44
-rw-r--r--desktop-utilities/lumina-terminal/TtyProcess.h3
4 files changed, 54 insertions, 11 deletions
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 <QTextEdit>
#include <QKeyEvent>
+#include <QResizeEvent>
#include <QSocketNotifier>
#include <QTimer>
@@ -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; i<raw.size() && end==0; i++){
+ if(raw.size() < index+i){ return raw; }//cut off - go back for more data
+ //qDebug() << "Check Char:" << raw.at(index+i);
+ if( QChar(raw.at(index+i)).isLetter() ){
+ end = i; //found the end of the control code
+ }
+ }
+ raw = raw.remove(index, 1+end); //control character +1 byte
index = raw.indexOf("\x1B[");
}
//qDebug() << " - Removed Color Codes:" << raw;
@@ -151,8 +174,7 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
raw = raw.remove(index,1);
index = raw.indexOf("\x07");
}
- //qDebug() << " - Fully Cleaned:" << raw;
-
+
incomplete = false;
return raw;
}
@@ -178,7 +200,7 @@ pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
//Adjust the slave side mode to RAW
struct termios TSET;
rc = tcgetattr(fds, &TSET); //read the current settings
- cfmakeraw(&TSET); //set the RAW mode on the settings
+ cfmakesane(&TSET); //set the RAW mode on the settings ( cfmakeraw(&TSET); )
tcsetattr(fds, TCSANOW, &TSET); //apply the changed settings
//Change the controlling terminal in child thread to the slave PTY
diff --git a/desktop-utilities/lumina-terminal/TtyProcess.h b/desktop-utilities/lumina-terminal/TtyProcess.h
index ba5606de..04f294a2 100644
--- a/desktop-utilities/lumina-terminal/TtyProcess.h
+++ b/desktop-utilities/lumina-terminal/TtyProcess.h
@@ -40,6 +40,9 @@ public:
void writeQtKey(int key); //simplification function for handling special keys like arrows and such ( QKeyEvent()->key() )
QByteArray readTTY();
+ //Setup the terminal size (characters and pixels)
+ void setTerminalSize(QSize chars, QSize pixels);
+
//Status update checks
bool isOpen();
bgstack15