Allow direct terminal typing and collapsible session panels
This commit is contained in:
78
src/terminal_view.cpp
Normal file
78
src/terminal_view.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include "terminal_view.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QKeyEvent>
|
||||
|
||||
TerminalView::TerminalView(QWidget* parent) : QPlainTextEdit(parent)
|
||||
{
|
||||
setReadOnly(true);
|
||||
setUndoRedoEnabled(false);
|
||||
}
|
||||
|
||||
void TerminalView::keyPressEvent(QKeyEvent* event)
|
||||
{
|
||||
if (event == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const Qt::KeyboardModifiers modifiers = event->modifiers();
|
||||
|
||||
if (modifiers == Qt::ControlModifier) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_C:
|
||||
emit inputGenerated(QStringLiteral("\x03"));
|
||||
return;
|
||||
case Qt::Key_D:
|
||||
emit inputGenerated(QStringLiteral("\x04"));
|
||||
return;
|
||||
case Qt::Key_L:
|
||||
emit inputGenerated(QStringLiteral("\x0c"));
|
||||
return;
|
||||
case Qt::Key_V: {
|
||||
const QString clipboardText = QApplication::clipboard()->text();
|
||||
if (!clipboardText.isEmpty()) {
|
||||
emit inputGenerated(clipboardText);
|
||||
}
|
||||
return;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Return:
|
||||
case Qt::Key_Enter:
|
||||
emit inputGenerated(QStringLiteral("\n"));
|
||||
return;
|
||||
case Qt::Key_Backspace:
|
||||
emit inputGenerated(QStringLiteral("\x7f"));
|
||||
return;
|
||||
case Qt::Key_Tab:
|
||||
emit inputGenerated(QStringLiteral("\t"));
|
||||
return;
|
||||
case Qt::Key_Left:
|
||||
emit inputGenerated(QStringLiteral("\x1b[D"));
|
||||
return;
|
||||
case Qt::Key_Right:
|
||||
emit inputGenerated(QStringLiteral("\x1b[C"));
|
||||
return;
|
||||
case Qt::Key_Up:
|
||||
emit inputGenerated(QStringLiteral("\x1b[A"));
|
||||
return;
|
||||
case Qt::Key_Down:
|
||||
emit inputGenerated(QStringLiteral("\x1b[B"));
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const QString text = event->text();
|
||||
if (!text.isEmpty()) {
|
||||
emit inputGenerated(text);
|
||||
return;
|
||||
}
|
||||
|
||||
QPlainTextEdit::keyPressEvent(event);
|
||||
}
|
||||
Reference in New Issue
Block a user