aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-terminal
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-terminal')
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp89
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h3
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp44
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TtyProcess.h1
4 files changed, 94 insertions, 43 deletions
diff --git a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
index e009b1c0..a4622817 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
@@ -14,6 +14,8 @@
#include <LuminaXDG.h>
+#define DEBUG 0
+
//Special control code ending symbols (aside from letters)
TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent){
@@ -30,6 +32,10 @@ TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent)
this->setTabStopWidth( 8 * this->fontMetrics().width(" ") ); //8 character spaces per tab (UNIX standard)
//this->setWordWrapMode(QTextOption::NoWrap);
this->setContextMenuPolicy(Qt::CustomContextMenu);
+ resizeTimer = new QTimer(this);
+ resizeTimer->setInterval(20);
+ resizeTimer->setSingleShot(true);
+ connect(resizeTimer, SIGNAL(timeout()), this, SLOT(updateTermSize()) );
DEFFMT = this->textCursor().charFormat(); //save the default structure for later
DEFFMT.setForeground(Qt::white);
CFMT = DEFFMT; //current format
@@ -49,7 +55,7 @@ TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent)
//int fd;
bool ok = PROC->startTTY( QProcessEnvironment::systemEnvironment().value("SHELL","/bin/sh"), QStringList(), dir);
//qDebug() << " - opened:" << ok;
- this->setEnabled(PROC->isOpen());
+ this->setEnabled(false);
contextMenu = new QMenu(this);
copyA = contextMenu->addAction(LXDG::findIcon("edit-copy"), tr("Copy Selection"), this, SLOT(copySelection()) );
pasteA = contextMenu->addAction(LXDG::findIcon("edit-paste"), tr("Paste"), this, SLOT(pasteSelection()) );
@@ -64,6 +70,7 @@ TerminalWidget::~TerminalWidget(){
}
void TerminalWidget::setTerminalFont(QFont font){
+
this->setFont(font);
}
@@ -80,20 +87,26 @@ void TerminalWidget::InsertText(QString txt){
if(txt.isEmpty()){ return; }
//qDebug() << "Insert Text:" << txt << "Cursor Pos:" << this->textCursor().position() << "Column:" << this->textCursor().columnNumber();
QTextCursor cur = this->textCursor();
+ cur.setCharFormat(CFMT);
+ this->setTextCursor(cur); //ensure the current cursor has the proper format
this->insertPlainText(txt);
- cur.setPosition( this->textCursor().position(), QTextCursor::KeepAnchor);
- cur.setCharFormat(CFMT);
+ /*cur.setPosition( this->textCursor().position(), QTextCursor::KeepAnchor);
+ //cur.setCharFormat(CFMT);
//Now make sure the new characters are the right color
QList<QTextEdit::ExtraSelection> sels = this->extraSelections();
QTextEdit::ExtraSelection sel;
sel.format = CFMT;
sel.cursor = cur;
sels << sel;
- this->setExtraSelections(sels);
- //qDebug() << "New Text Format:"<< txt << CFMT.foreground() << CFMT.font() << CFMT.fontWeight();
+ this->setExtraSelections(sels);*/
+ if(DEBUG){
+ qDebug() << "Insert Text:"<< txt << "Font Color:" << CFMT.foreground() << "Background Color:" << CFMT.background() << "Font Weight:" << CFMT.fontWeight();
+ }
}
void TerminalWidget::applyData(QByteArray data){
+ this->setEnabled(true);
+ if(DEBUG){ qDebug() << "Got Data: " << data; }
//Make sure the current cursor is the right cursor
if(this->textCursor()==selCursor){ this->setTextCursor(lastCursor); }
//Iterate through the data and apply it when possible
@@ -127,12 +140,15 @@ void TerminalWidget::applyData(QByteArray data){
//qDebug() << "Code:" << data.mid(i+1, end) << "Next Char:" << data[i+end+2];
i+=end; //move the final loop along - already handled these bytes
- }else if( data.at(i) != '\r' ){
- chars.append(data.at(i));
- //Plaintext character - just add it here
- //qDebug() << "Insert Text:" << data.at(i) << CFMT.foreground().color() << CFMT.background().color();
- //qDebug() << " " << this->currentCharFormat().foreground().color() << this->currentCharFormat().background().color();
- //this->textCursor().insertText( QChar(data.at(i)), CFMT );
+ }else if( data.at(i) == '\r' ){
+ //Move cursor to end of line
+ //qDebug() << "Got a return char";
+ QTextCursor cur = this->textCursor();
+ cur.movePosition(QTextCursor::EndOfLine, QTextCursor::MoveAnchor, 1);
+ cur.removeSelectedText();
+ this->setTextCursor(cur);
+ }else{
+ chars.append(data.at(i)); //Add the character to the buffer
}
} //end loop over data
if(!chars.isEmpty()){ InsertText(chars); }
@@ -282,7 +298,18 @@ void TerminalWidget::applyANSI(QByteArray code){
cur.removeSelectedText();
this->setTextCursor(cur);
}
-
+ }else if(code.endsWith("g")){
+ //Tab Clear codes (0 or 3 only)
+ int num = 0;
+ if(code.size()>2){ num = code.mid(1, code.size()-2).toInt(); } //everything in the middle
+ if(num==0){ //clear current column (delete key analogue)
+ QTextCursor cur = this->textCursor();
+ cur.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1);
+ cur.removeSelectedText();
+ this->setTextCursor(cur);
+ }else if(num==3){ //clear all
+ this->clear();
+ }
//SCROLL MOVEMENT CODES
//}else if(code.endsWith("S")){ // SU - Scroll Up
//qDebug() << "Scroll Up:" << code;
@@ -292,16 +319,22 @@ void TerminalWidget::applyANSI(QByteArray code){
// GRAPHICS RENDERING
}else if(code.endsWith("m")){
//Format: "[<number>;<number>m" (no limit to sections separated by ";")
+ //qDebug() << "Got Graphics Code:" << code;
+ code.chop(1); //chop the "m" off the end
int start = 1;
int end = code.indexOf(";");
while(end>start){
+ //qDebug() << "Color Code:" << code << start << end << code.mid(start, end-start);
applyANSIColor(code.mid(start, end-start).toInt());
//Now update the iterators and try again
start = end;
- end = code.indexOf(";",start+1); //go to the next one
+ end = code.indexOf(";",start); //go to the next one
+ //qDebug() << "Next end:" << end;
}
//Need the last section as well
- end = code.size()-1;
+ end = code.size();
+ if(start>1){ start ++; }
+ //qDebug() << "Color Code:" << code << start << end << code.mid(start, end-start);
if(end>start){ applyANSIColor(code.mid(start, end-start).toInt());}
else{ applyANSIColor(0); }
@@ -356,11 +389,11 @@ void TerminalWidget::applyANSIColor(int code){
else if(code==37){ color=QColor(Qt::white); }
//48: Special extended color setting (unsupported)
else if(code==39){ color= DEFFMT.foreground().color(); } //reset to default color
-QBrush brush = CFMT.background();
+ QBrush brush = CFMT.foreground();
color.setAlpha(255); //fully opaque
brush.setColor(color);
CFMT.setForeground( brush );
- this->setTextColor(color); //just in case the format is not used
+ //this->setTextColor(color); //just in case the format is not used
}
else if(code>=40 && code<=49){
//Set the font color
@@ -388,6 +421,7 @@ QBrush brush = CFMT.background();
else if(code==55){ CFMT.setFontOverline(false); } //disable overline
//56-59: Reserved
//60+: Not generally supported (special code for particular terminals such as aixterm)
+ else{ qDebug() << "Unknown Color Code:" << code; }
}
//Outgoing Data parsing
@@ -440,7 +474,6 @@ void TerminalWidget::UpdateText(){
applyData(PROC->readTTY());
//adjust the scrollbar as needed
this->ensureCursorVisible();
- //this->verticalScrollBar()->setValue(this->verticalScrollBar()->maximum());
}
void TerminalWidget::ShellClosed(){
@@ -461,6 +494,16 @@ void TerminalWidget::pasteSelection(){
}
}
+void TerminalWidget::updateTermSize(){
+ if(!PROC->isOpen()){ return; }
+ QSize pix = this->size(); //pixels
+ QSize chars;
+ chars.setWidth( pix.width()/this->fontMetrics().width("W") );
+ chars.setHeight( pix.height()/this->fontMetrics().lineSpacing() );
+
+ PROC->setTerminalSize(chars,pix);
+}
+
// ==================
// PROTECTED
// ==================
@@ -468,11 +511,7 @@ void TerminalWidget::keyPressEvent(QKeyEvent *ev){
if(ev->text().isEmpty() || ev->text()=="\b" ){
sendKeyPress(ev->key());
- //PROC->writeTTY( QByteArray::fromHex(ev->nativeVirtualKey()) );
}else{
- if( (ev->key()==Qt::Key_Enter || ev->key()==Qt::Key_Return) && !this->textCursor().atEnd() ){
- sendKeyPress(Qt::Key_End); //just in case the cursor is not at the end (TTY will split lines and such - ugly)
- }
QByteArray ba; ba.append(ev->text()); //avoid any byte conversions
//qDebug() << "Forward Input:" << ba;
PROC->writeTTY(ba);
@@ -524,12 +563,6 @@ void TerminalWidget::mouseDoubleClickEvent(QMouseEvent *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);
+ resizeTimer->start();
QTextEdit::resizeEvent(ev);
}
diff --git a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
index 16509cb4..616919c3 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
+++ b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
@@ -28,6 +28,7 @@ public:
private:
TTYProcess *PROC;
+ QTimer *resizeTimer;
QTextCharFormat DEFFMT, CFMT; //default/current text format
QTextCursor selCursor, lastCursor;
QMenu *contextMenu;
@@ -54,6 +55,8 @@ private slots:
void copySelection();
void pasteSelection();
+ void updateTermSize();
+
signals:
void ProcessClosed(QString);
diff --git a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
index 6fddee39..6ddd876b 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
+++ b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
@@ -24,10 +24,14 @@ bool TTYProcess::startTTY(QString prog, QStringList args, QString workdir){
QDir::setCurrent(workdir);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
setenv("TERM","vt220-color",1);//"vt102-color",1); //vt100: VT100 emulation support (QTerminal sets "xterm" here)
- //unsetenv("TERM");
- unsetenv("TERMCAP");
- //setenv("TERMCAP","xterm",1);
- /*setenv("TERMCAP",":do=2\E[B:co#80:li#24:cl=50\E[H\E[J:sf=2*\ED:\
+
+ //setenv("TERMINFO","/etc/termcap",0);
+ unsetenv("WINDOWID");
+ //unsetenv("TERMCAP");
+ //setenv("TERMCAP","/etc/termcap",1);
+ //setenv("TERMCAP","vt220-color",1);
+ //setenv("TERMCAP","vt102|vt220-color|dec vt102:' :do=^J:co#80:li#24:cl=50\E[;H\E[2J: :le=^H:bs:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A: :ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m: :md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:is=\E[1;24r\E[24;1H: :rs=\E>\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h:ks=\E[?1h\E=:ke=\E[?1l\E>: :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H: :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3: :sc=\E7:rc=\E8:cs=\E[%i%d;%dr:vs=\E[?7l:ve=\E[?7h: :mi:al=\E[L:dc=\E[P:dl=\E[M:ei=\E[4l:im=\E[4h:' vi $*",1);
+ /*setenv("TERMCAP","'vt220-color' :do=2\E[B:co#80:li#24:cl=50\E[H\E[J:sf=2*\ED:\
:le=^H:bs:am:cm=5\E[%i%d;%dH:nd=2\E[C:up=2\E[A:\
:ce=3\E[K:cd=50\E[J:so=2\E[7m:se=2\E[m:us=2\E[4m:ue=2\E[m:\
:md=2\E[1m:mr=2\E[7m:mb=2\E[5m:me=2\E[m:\
@@ -134,7 +138,7 @@ QByteArray TTYProcess::readTTY(){
//If the PTY gets input fairly soon after starting, the PTY will re-print the initial line(s)
if(starting && !BA.contains("\n") ){
//qDebug() << "Starting phase 1:" << BA;
- writeTTY("\n\b"); //newline + backspace
+ writeTTY("tset\n"); //Terminal Setup utility (uses the TERM env variable)
BA.clear();
}else if(starting){
//qDebug() << "Starting phase 2:" << BA;
@@ -178,7 +182,6 @@ 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();
@@ -233,7 +236,7 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
raw = raw.remove(index,1);
index = raw.indexOf("\x07");
}
- //VT220(?) print character code
+ //VT220(?) print character code (cut out the code, leave the character)
index=raw.indexOf("\x1b[@");
while(index>=0){
raw = raw.remove(index,3);
@@ -243,7 +246,7 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
//VT102 Identify request
index = raw.indexOf("\x1b[Z");
while(index>=0){
- raw = raw.remove(index,1);
+ raw = raw.remove(index,3);
index = raw.indexOf("\x1b[Z");
//Also send the proper reply to this identify request right away
writeTTY("\x1b[/Z");
@@ -251,7 +254,7 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
//Terminal Status request
index = raw.indexOf("\x1b[5n");
while(index>=0){
- raw = raw.remove(index,1);
+ raw = raw.remove(index,4);
index = raw.indexOf("\x1b[5n");
//Also send the proper reply to this identify request right away
writeTTY("\x1b[c"); //everything ok
@@ -259,9 +262,18 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
//Terminal Identify request
index = raw.indexOf("\x1b[c");
while(index>=0){
- raw = raw.remove(index,1);
+ raw = raw.remove(index,3);
index = raw.indexOf("\x1b[c");
//Also send the proper reply to this identify request right away
+ writeTTY("\x1b[1c"); //VT220 reply code
+ }
+ //Terminal Identify request (xterm/termcap?)
+ index = raw.indexOf("\x1b[P");
+ while(index>=0){
+ raw = raw.remove(index,3);
+ index = raw.indexOf("\x1b[P");
+ //Also send the proper reply to this identify request right away
+ qDebug() << " - Got XTERM/TERMCAP identify request ([P)";
writeTTY("\x1b[/Z");
}
@@ -272,28 +284,30 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
// === PRIVATE ===
pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
//Returns: -1 for errors, positive value (file descriptor) for the master side of the TTY to watch
-
//First open/setup a new pseudo-terminal file/device on the system (master side)
fd = posix_openpt(O_RDWR | O_NOCTTY); //open read/write
if(fd<0){ return -1; } //could not create pseudo-terminal
int rc = grantpt(fd); //set permissions
if(rc!=0){ return -1; }
rc = unlockpt(fd); //unlock file (ready for use)
+ //rc = fchown(fd, getuid(), getgid());
if(rc!=0){ return -1; }
//Now fork, return the Master device and setup the child
pid_t PID = fork();
if(PID==0){
//SLAVE/child
int fds = ::open(ptsname(fd), O_RDWR | O_NOCTTY); //open slave side read/write
- ::close(fd); //close the master side from the slave thread
+ //rc = fchown(fds, getuid(), getgid());
+ //::close(fd); //close the master side from the slave thread
- //Adjust the slave side mode to RAW
+ //Adjust the slave side mode to SANE
struct termios TSET;
rc = tcgetattr(fds, &TSET); //read the current settings
- cfmakesane(&TSET); //set the SANE mode on the settings ( cfmakeraw(&TSET); )
+ //cfmakesane(&TSET); //set the SANE mode on the settings ( RAW: cfmakeraw(&TSET); )
//Set Input Modes
TSET.c_iflag |= IGNPAR; //ignore parity errors
TSET.c_iflag &= ~(IGNBRK | PARMRK | ISTRIP | ICRNL | IXON | IXANY | IXOFF); //ignore special characters
+ //TSET.c_iflag &= IUTF8; //enable UTF-8 support
//Set Local Modes
TSET.c_lflag &= (ECHO | ECHONL | ECHOKE); //Echo inputs (normal, newline, and KILL character line break)
TSET.c_lflag &= ~ICANON ; //non-canonical mode (individual inputs - not a line-at-a-time)
@@ -309,7 +323,6 @@ pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
TSET.c_cc[VTIME] = 0; // timeout
//Now apply the settings
tcsetattr(fds, TCSANOW, &TSET); //apply the changed settings
-
//Change the controlling terminal in child thread to the slave PTY
::close(0); //close current terminal standard input
::close(1); //close current terminal standard output
@@ -322,6 +335,7 @@ pid_t TTYProcess::LaunchProcess(int& fd, char *prog, char **child_args){
ioctl(0,TIOCSCTTY, 1); //Set the controlling terminal to the slave PTY
//Execute the designated program
+ //rc = execvp("tset", NULL);
rc = execvp(prog, child_args);
::close(fds); //no need to keep original file descriptor open any more
exit(rc);
diff --git a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
index c2b483a9..97b4626b 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
+++ b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
@@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
+//#include <libutil.h>
class TTYProcess : public QObject{
Q_OBJECT
bgstack15