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/TermWindow.cpp13
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TermWindow.h1
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp45
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h1
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp104
-rw-r--r--src-qt5/desktop-utils/lumina-terminal/TtyProcess.h1
6 files changed, 128 insertions, 37 deletions
diff --git a/src-qt5/desktop-utils/lumina-terminal/TermWindow.cpp b/src-qt5/desktop-utils/lumina-terminal/TermWindow.cpp
index 8ff3ecd1..15cfe047 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TermWindow.cpp
+++ b/src-qt5/desktop-utils/lumina-terminal/TermWindow.cpp
@@ -36,6 +36,11 @@ TermWindow::TermWindow(QSettings *set) : QWidget(0, Qt::Window | Qt::BypassWindo
ANIM = new QPropertyAnimation(this, "geometry", this);
ANIM->setDuration(300); //1/3 second animation
connect(ANIM, SIGNAL(finished()), this, SLOT(AnimFinished()) );
+ activeTimer = new QTimer(this);
+ activeTimer->setInterval(50);
+ activeTimer->setSingleShot(true);
+ connect(activeTimer, SIGNAL(timeout()), this, SLOT(activeStatusChanged()) );
+ connect(QApplication::instance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), activeTimer, SLOT(start()) );
//Create the keyboard shortcuts
//hideS = new QShortcut(QKeySequence(Qt::Key_Escape),this);
closeS = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_Q),this);
@@ -57,7 +62,6 @@ TermWindow::TermWindow(QSettings *set) : QWidget(0, Qt::Window | Qt::BypassWindo
connect(closeS, SIGNAL(activated()), this, SLOT(CloseWindow()) );
connect(prevTabS, SIGNAL(activated()), this, SLOT(Prev_Tab()) );
connect(nextTabS, SIGNAL(activated()), this, SLOT(Next_Tab()) );
- connect(QApplication::instance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(activeStatusChanged()) );
//Now set the defaults
screennum = 0; //default value
setTopOfScreen(true); //default value
@@ -283,12 +287,9 @@ void TermWindow::AnimFinished(){
}
void TermWindow::activeStatusChanged(){
- //Note: Qt 5.6.1 returns the opposite value for isActiveWindow() (12/7/16)
- //qDebug() << "active status changed:" << this->isActiveWindow() << (this == QApplication::activeWindow());
if(animRunning>=0){ return; } //ignore this event - already changing
- //if(!this->isActiveWindow() && !this->isVisible()){ ShowWindow(); }
- //else if(this->isActiveWindow() this->isVisible()){ HideWindow(); }
- //ReShowWindow();
+ QWidget *active = QApplication::activeWindow();
+ if(active==0 && this->isVisible()){ HideWindow(); }
}
// ===================
diff --git a/src-qt5/desktop-utils/lumina-terminal/TermWindow.h b/src-qt5/desktop-utils/lumina-terminal/TermWindow.h
index d21fe502..5f583126 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TermWindow.h
+++ b/src-qt5/desktop-utils/lumina-terminal/TermWindow.h
@@ -41,6 +41,7 @@ private:
bool onTop, CLOSING;
QPropertyAnimation *ANIM;
int animRunning; //internal flag for what animation is currently running
+ QTimer *activeTimer;
//Calculate the window geometry necessary based on screen/location
void CalculateGeom();
diff --git a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
index 6342be59..83474f04 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
+++ b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.cpp
@@ -19,7 +19,10 @@
TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent){
//Setup the text widget
closing = false;
- this->setStyleSheet("QTextEdit{ background: black; color: white; }");
+ QPalette P = this->palette();
+ P.setColor(QPalette::Base, Qt::black);
+ P.setColor(QPalette::Text, Qt::white);
+ this->setPalette(P);
this->setLineWrapMode(QTextEdit::WidgetWidth);
this->setAcceptRichText(false);
this->setOverwriteMode(true);
@@ -37,14 +40,15 @@ TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent)
QFontDatabase FDB;
QStringList fonts = FDB.families(QFontDatabase::Latin);
for(int i=0; i<fonts.length(); i++){
- if(FDB.isFixedPitch(fonts[i])){ this->setFont(QFont(fonts[i])); qDebug() << "Using Font:" << fonts[i]; break; }
+ if(FDB.isFixedPitch(fonts[i]) && FDB.isSmoothlyScalable(fonts[i]) ){ this->setFont(QFont(fonts[i])); qDebug() << "Using Font:" << fonts[i]; break; }
+ //if(FDB.isSmoothlyScalable(fonts[i]) ){ this->setFont(QFont(fonts[i])); qDebug() << "Using Font:" << fonts[i]; break; }
}
//Create/open the TTY port
PROC = new TTYProcess(this);
- qDebug() << "Open new TTY";
+ //qDebug() << "Open new TTY";
//int fd;
bool ok = PROC->startTTY( QProcessEnvironment::systemEnvironment().value("SHELL","/bin/sh"), QStringList(), dir);
- qDebug() << " - opened:" << ok;
+ //qDebug() << " - opened:" << ok;
this->setEnabled(PROC->isOpen());
contextMenu = new QMenu(this);
copyA = contextMenu->addAction(LXDG::findIcon("edit-copy"), tr("Copy Selection"), this, SLOT(copySelection()) );
@@ -59,10 +63,14 @@ TerminalWidget::~TerminalWidget(){
aboutToClose();
}
+void TerminalWidget::setTerminalFont(QFont font){
+ this->setFont(font);
+}
+
void TerminalWidget::aboutToClose(){
closing = true;
if(PROC->isOpen()){ PROC->closeTTY(); } //TTY PORT
- //delete PROC->
+
}
// ==================
@@ -82,7 +90,7 @@ void TerminalWidget::InsertText(QString txt){
sel.cursor = cur;
sels << sel;
this->setExtraSelections(sels);
- //qDebug() << "New Text. Format:" << CFMT.foreground() << CFMT.font();
+ //qDebug() << "New Text Format:"<< txt << CFMT.foreground() << CFMT.font() << CFMT.fontWeight();
}
void TerminalWidget::applyData(QByteArray data){
@@ -93,10 +101,15 @@ void TerminalWidget::applyData(QByteArray data){
//qDebug() << "Data:" << data;
for(int i=0; i<data.size(); i++){
if( data.at(i)=='\b' ){
- //Flush current text buffer to widget
- //Simple cursor backward 1 (NOT backspace in this context!! - this widget should be in "insert" mode instead)
- InsertText(chars); chars.clear();
- this->moveCursor(QTextCursor::Left, QTextCursor::MoveAnchor);
+ //Backspace
+ if(!chars.isEmpty()){ chars.chop(1); }
+ else{
+ QTextCursor cur = this->textCursor();
+ cur.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
+ cur.removeSelectedText();
+ this->setTextCursor(cur);
+ }
+
//}else if( data.at(i)=='\t' ){
//chars.append(" ");
}else if( data.at(i)=='\x1B' ){
@@ -115,10 +128,6 @@ void TerminalWidget::applyData(QByteArray data){
i+=end; //move the final loop along - already handled these bytes
}else if( data.at(i) != '\r' ){
- //Special Check: if inserting text within a line, clear the rest of this line first
- if(i==0 && this->textCursor().position() < this->document()->characterCount()-1){
- applyANSI("[K");
- }
chars.append(data.at(i));
//Plaintext character - just add it here
//qDebug() << "Insert Text:" << data.at(i) << CFMT.foreground().color() << CFMT.background().color();
@@ -131,7 +140,7 @@ void TerminalWidget::applyData(QByteArray data){
void TerminalWidget::applyANSI(QByteArray code){
//Note: the first byte is often the "[" character
- qDebug() << "Handle ANSI:" << code;
+ //qDebug() << "Handle ANSI:" << code;
if(code.length()==1){
//KEYPAD MODES
if(code.at(0)=='='){ altkeypad = true; }
@@ -414,7 +423,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); }
}
@@ -484,9 +493,11 @@ void TerminalWidget::mousePressEvent(QMouseEvent *ev){
}
void TerminalWidget::mouseMoveEvent(QMouseEvent *ev){
- if(ev->button()==Qt::LeftButton){
+ //qDebug() << "MouseMove Event" << ev->button() << ev->buttons() << Qt::LeftButton;
+ if(ev->buttons().testFlag(Qt::LeftButton) ){
selCursor.setPosition(this->cursorForPosition(ev->pos()).position(), QTextCursor::KeepAnchor);
if(selCursor.hasSelection()){ this->setTextCursor(selCursor); }
+ //qDebug() << "Mouse Movement:" << selCursor.hasSelection();
}else{
QTextEdit::mouseMoveEvent(ev);
}
diff --git a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
index bdec606b..16509cb4 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
+++ b/src-qt5/desktop-utils/lumina-terminal/TerminalWidget.h
@@ -23,6 +23,7 @@ public:
TerminalWidget(QWidget *parent =0, QString dir="");
~TerminalWidget();
+ void setTerminalFont(QFont);
void aboutToClose();
private:
diff --git a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
index a1ee0be7..88eeb1ec 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
+++ b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.cpp
@@ -4,11 +4,14 @@
#include <QProcessEnvironment>
#include <QTimer>
+#define DEBUG 0
+
TTYProcess::TTYProcess(QObject *parent) : QObject(parent){
childProc = 0;
sn = 0;
ttyfd = 0;
starting = true;
+ fixReply = -1;
}
TTYProcess::~TTYProcess(){
@@ -20,10 +23,26 @@ bool TTYProcess::startTTY(QString prog, QStringList args, QString workdir){
if(workdir=="~"){ workdir = QDir::homePath(); }
QDir::setCurrent(workdir);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- setenv("TERM","xterm",1);//"vt100",1); //vt100: VT100 emulation support
- unsetenv("TERMCAP");
- /*setenv("TERMCAP","mvterm|vv100|mvterm emulator with ANSI colors:\
- :pa#64:Co#8:AF=\E[3%dm:AB=\E[4%dm:op=\E[100m:tc=vt102:",1); //see /etc/termcap as well*/
+ 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:\
+ :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:\
+ :is=\E>\E[?1;3;4;5l\E[?7;8h\E[1;24r\E[24;1H:\
+ :if=/usr/share/tabset/vt100:nw=2\EE:ho=\E[H:\
+ :as=2\E(0:ae=2\E(B:\
+ :ac=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||:\
+ :rs=\E>\E[?1;3;4;5l\E[?7;8h:ks=\E[?1h\E=:ke=\E[?1l\E>:\
+ :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=\177:\
+ :k0=\EOy:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:k5=\EOt:\
+ :k6=\EOu:k7=\EOv:k8=\EOl:k9=\EOw:k;=\EOx:@8=\EOM:\
+ :K1=\EOq:K2=\EOr:K3=\EOs:K4=\EOp:K5=\EOn:pt:sr=2*\EM:xn:\
+ :sc=2\E7:rc=2\E8:cs=5\E[%i%d;%dr:UP=2\E[%dA:DO=2\E[%dB:RI=2\E[%dC:\
+ :LE=2\E[%dD:ct=2\E[3g:st=2\EH:ta=^I:ms:bl=^G:cr=^M:eo:it#8:\
+ :RA=\E[?7l:SA=\E[?7h:po=\E[5i:pf=\E[4i:",1); //see /etc/termcap as well*/
QStringList filter = env.keys().filter("XTERM");
for(int i=0; i<filter.length(); i++){ unsetenv(filter[i].toLocal8Bit().data()); }
//if(env.contains("TERM")){ unsetenv("TERM"); }
@@ -44,12 +63,14 @@ bool TTYProcess::startTTY(QString prog, QStringList args, QString workdir){
cargs[i] = NULL;
}
}
- qDebug() << "PTY Start:" << prog;
+ if(DEBUG){ qDebug() << "PTY Start:" << prog; }
//Launch the process attached to a new PTY
int FD = 0;
pid_t tmp = LaunchProcess(FD, cprog, cargs);
- qDebug() << " - PID:" << tmp;
- qDebug() << " - FD:" << FD;
+ if(DEBUG){
+ qDebug() << " - PID:" << tmp;
+ qDebug() << " - FD:" << FD;
+ }
if(tmp<0){ return false; } //error
else{
childProc = tmp;
@@ -60,13 +81,8 @@ bool TTYProcess::startTTY(QString prog, QStringList args, QString workdir){
sn->setEnabled(true);
connect(sn, SIGNAL(activated(int)), this, SLOT(checkStatus(int)) );
ttyfd = FD;
- qDebug() << " - PTY:" << ptsname(FD);
- //BUG BYPASS - 12/7/16
- //If the PTY gets input fairly soon after starting, the PTY will re-print the initial line(s)
- // So send the "newline" signal now to get things started
+ if(DEBUG){ qDebug() << " - PTY:" << ptsname(FD); }
starting = true;
- //writeTTY("\n"); //newline
- //writeTTY(QByteArray("\x1b[2J") ); //clear display
return true;
}
}
@@ -86,6 +102,9 @@ void TTYProcess::closeTTY(){
void TTYProcess::writeTTY(QByteArray output){
//qDebug() << "Write:" << output;
+ static QList<QByteArray> knownFixes;
+ if(knownFixes.isEmpty()){ knownFixes << "\x1b[C" << "\x1b[D" << "\b" << "\x7F" << "\x08"; }
+ fixReply = knownFixes.indexOf(output);
::write(ttyfd, output.data(), output.size());
}
@@ -110,7 +129,9 @@ QByteArray TTYProcess::readTTY(){
fragBA = BA;
return readTTY();
}else{
- //qDebug() << "Read Data:" << BA;
+ if(DEBUG){ qDebug() << "Read Data:" << BA; }
+ //BUG BYPASS - 12/7/16
+ //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
@@ -120,6 +141,37 @@ QByteArray TTYProcess::readTTY(){
BA.remove(0, BA.indexOf("\n")+1);
starting = false;
}
+ //Apply known fixes for replies to particular inputs (mostly related to cursor position *within* the current line)
+ // This appears to be primarily from the concept that the cursor position is always at the end of the line (old VT limitation?)
+ // so almost all these fixes are for cursor positioning within the current line
+ if(fixReply >= 0){
+ if(DEBUG){ qDebug() << "Fix Reply:" <<fixReply << BA; }
+ switch(fixReply){
+ case 0: //Right arrow ("\x1b[C") - PTY reply re-prints the next character rather than moving the cursor
+ if(BA.length()>0){
+ BA.remove(0,1);
+ BA.prepend("\x1b[C"); //just move the cursor - don't re-print that 1 character
+ }
+ break;
+ case 1: //Left arrow ("\x1b[D") - PTY erases the previous character instead of moving the cursor
+ if(BA.startsWith("\b")){
+ BA.remove(0,1);
+ BA.prepend("\x1b[D"); //just move the cursor - don't send the "back" character (\b)
+ }
+ break;
+ case 2: //Backspace or delete - PTY works fine if on the end of the line, but when in the middle of a line it will backpace a number of times after clearing (same as left arrow issue)
+ case 3:
+ case 4:
+ if(BA.contains("\x1b[K")){
+ while(BA.indexOf("\x1b[K") < BA.lastIndexOf("\b") ){
+ BA.replace( BA.lastIndexOf("\b"), 1, "\x1b[D"); //just move the cursor left - don't send the "back" character (\b)
+ }
+ }
+ break;
+ }
+ fixReply = -1; //done with the fix - resume normal operations
+ if(DEBUG){ qDebug() << " - Fixed:" << BA; }
+ }
return BA;
}
}
@@ -182,6 +234,30 @@ QByteArray TTYProcess::CleanANSI(QByteArray raw, bool &incomplete){
index = raw.indexOf("\x07");
}
+ //VT102 Identify request
+ index = raw.indexOf("\x1b[Z");
+ while(index>=0){
+ raw = raw.remove(index,1);
+ index = raw.indexOf("\x1b[Z");
+ //Also send the proper reply to this identify request right away
+ writeTTY("\x1b[/Z");
+ }
+//Terminal Status request
+ index = raw.indexOf("\x1b[5n");
+ while(index>=0){
+ raw = raw.remove(index,1);
+ index = raw.indexOf("\x1b[5n");
+ //Also send the proper reply to this identify request right away
+ writeTTY("\x1b[c"); //everything ok
+ }
+//Terminal Identify request
+ index = raw.indexOf("\x1b[c");
+ while(index>=0){
+ raw = raw.remove(index,1);
+ index = raw.indexOf("\x1b[?1;7c");
+ //Also send the proper reply to this identify request right away
+ writeTTY("\x1b[/Z");
+ }
incomplete = false;
return raw;
}
diff --git a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
index 1603fe5e..c2b483a9 100644
--- a/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
+++ b/src-qt5/desktop-utils/lumina-terminal/TtyProcess.h
@@ -61,6 +61,7 @@ private:
QSocketNotifier *sn;
QByteArray fragBA; //fragment ByteArray
bool starting;
+ int fixReply; //flag for detecting particular inputs and "fixing" the reply to it as needed
//====================================
// C Library function for setting up the PTY
bgstack15