aboutsummaryrefslogtreecommitdiff
path: root/desktop-utilities/lumina-terminal/TerminalWidget.cpp
diff options
context:
space:
mode:
authorKen Moore <moorekou@gmail.com>2015-09-17 12:23:59 -0400
committerKen Moore <moorekou@gmail.com>2015-09-17 12:23:59 -0400
commit849295c448bd70b54d4ca2aa8b6269ae58e4ae4c (patch)
treef5f075a6cfd1a0820f034ec5e8116df477fd6dd3 /desktop-utilities/lumina-terminal/TerminalWidget.cpp
parentMake the snapshot load/reload operations "active", in that it will detect whe... (diff)
downloadlumina-849295c448bd70b54d4ca2aa8b6269ae58e4ae4c.tar.gz
lumina-849295c448bd70b54d4ca2aa8b6269ae58e4ae4c.tar.bz2
lumina-849295c448bd70b54d4ca2aa8b6269ae58e4ae4c.zip
Add my work-in-progress for a lumina-terminal application. This is *not* ready to be distributed yet, only the basic application wrapper is functional (no terminal functionality yet).
Diffstat (limited to 'desktop-utilities/lumina-terminal/TerminalWidget.cpp')
-rw-r--r--desktop-utilities/lumina-terminal/TerminalWidget.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/desktop-utilities/lumina-terminal/TerminalWidget.cpp b/desktop-utilities/lumina-terminal/TerminalWidget.cpp
new file mode 100644
index 00000000..4cfd3849
--- /dev/null
+++ b/desktop-utilities/lumina-terminal/TerminalWidget.cpp
@@ -0,0 +1,83 @@
+//===========================================
+// Lumina-DE source code
+// Copyright (c) 2015, Ken Moore
+// Available under the 3-clause BSD license
+// See the LICENSE file for full details
+//===========================================
+#include "TerminalWidget.h"
+
+#include <QProcessEnvironment>
+#include <QDebug>
+#include <QApplication>
+
+TerminalWidget::TerminalWidget(QWidget *parent, QString dir) : QTextEdit(parent){
+ //Setup the text widget
+ this->setLineWrapMode(QTextEdit::WidgetWidth);
+ this->setReadOnly(true); //the key event catch will do the process/widget forwarding
+ this->setPlainText("WARNING: This utility is still incomplete and does not function properly yet");
+ //Create/launch the process
+ PROC = new QProcess(this);
+ PROC->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
+ PROC->setWorkingDirectory(dir);
+ PROC->setProcessChannelMode(QProcess::MergedChannels);
+ //Connect the signals/slots
+ connect(PROC, SIGNAL(readyReadStandardOutput()), this, SLOT(UpdateText()) );
+ connect(PROC, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(ShellClosed()) );
+ //Now start the shell
+ PROC->start( PROC->processEnvironment().value("SHELL","/bin/sh"), QIODevice::ReadWrite);
+
+}
+
+TerminalWidget::~TerminalWidget(){
+
+}
+
+void TerminalWidget::aboutToClose(){
+ if(PROC->state()!=QProcess::NotRunning){ PROC->close(); }
+ if(PROC->state()!=QProcess::NotRunning){ PROC->kill(); }
+ if(PROC->state()!=QProcess::NotRunning){ PROC->terminate(); }
+}
+
+// ==================
+// PRIVATE SLOTS
+// ==================
+void TerminalWidget::UpdateText(){
+ while(PROC->canReadLine()){
+ QString line = PROC->readLine();
+ this->insertPlainText( line );
+ }
+}
+
+void TerminalWidget::ShellClosed(){
+ emit ProcessClosed(this->whatsThis());
+}
+
+// ==================
+// PROTECTED
+// ==================
+void TerminalWidget::keyPressEvent(QKeyEvent *ev){
+ //The way this works is by printing the keys directly to the text edit widget
+ // While also keeping an internal "buffer" of the input string so it can all be written to the process at the same time
+
+ QString key = ev->text();
+ //Check for special key combinations first
+ switch(ev->key()){
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ //send the current input buffer to the process
+ qDebug() << "Write to process:" << inBuffer;
+ this->insertPlainText("\n");
+ PROC->write( QString(inBuffer+"\n").toLocal8Bit() );
+ inBuffer.clear();
+ qDebug() << "Current Dir:" << PROC->workingDirectory();
+ break;
+ case Qt::Key_Backspace:
+ inBuffer.chop(1);
+ break;
+ default:
+ this->insertPlainText(key);
+ inBuffer.append(key);
+ }
+
+ ev->ignore();
+} \ No newline at end of file
bgstack15