Commit 9ceae8d1 authored by Sebastian Badur's avatar Sebastian Badur
Browse files

Add openTeletype option for use without shell

The user might want to open a teletype in a Session or a Part without an additional shell interfering / in background (e.g. pty to /bin/vi).
Therefore, a new optional argument is introduced to run a pty process standalone. Consistency is held with legacy method calls.
parent 340d8fc0
......@@ -133,11 +133,11 @@ void Part::startProgram(const QString &program, const QStringList &arguments)
activeSession()->run();
}
void Part::openTeletype(int ptyMasterFd)
void Part::openTeletype(int ptyMasterFd, bool runShell)
{
Q_ASSERT(activeSession());
activeSession()->openTeletype(ptyMasterFd);
activeSession()->openTeletype(ptyMasterFd, runShell);
}
void Part::showShellInDir(const QString &dir)
......
......@@ -135,8 +135,11 @@ public Q_SLOTS:
* or showShellInDir()
*
* @param ptyMasterFd The file descriptor of the pseudo-teletype (pty) master
* @param runShell When true (default, legacy), runs the teletype in a shell
* session environment. When false, the session is not run, so that the
* KPtyProcess can be standalone, which may be useful for interactive programs.
*/
void openTeletype(int ptyMasterFd);
void openTeletype(int ptyMasterFd, bool runShell = true);
/**
* Toggles monitoring for silence in the active session. If silence is detected,
......
......@@ -136,7 +136,7 @@ Session::Session(QObject* parent) :
connect(_emulation, &Konsole::Emulation::sessionAttributeRequest, this, &Konsole::Session::sessionAttributeRequest);
//create new teletype for I/O with shell process
openTeletype(-1);
openTeletype(-1, true);
//setup timer for monitoring session activity & silence
_silenceTimer = new QTimer(this);
......@@ -157,7 +157,7 @@ Session::~Session()
delete _zmodemProc;
}
void Session::openTeletype(int fd)
void Session::openTeletype(int fd, bool runShell)
{
if (isRunning()) {
qWarning() << "Attempted to open teletype in a running session.";
......@@ -189,7 +189,12 @@ void Session::openTeletype(int fd)
// emulator size
// Use a direct connection to ensure that the window size is set before it runs
connect(_emulation, &Konsole::Emulation::imageSizeChanged, this, &Konsole::Session::updateWindowSize, Qt::DirectConnection);
connect(_emulation, &Konsole::Emulation::imageSizeInitialized, this, &Konsole::Session::run);
if (fd < 0 || runShell) {
connect(_emulation, &Konsole::Emulation::imageSizeInitialized, this, &Konsole::Session::run);
} else {
// run needs to be disconnected, as it may be already connected by the constructor
disconnect(_emulation, &Konsole::Emulation::imageSizeInitialized, this, &Konsole::Session::run);
}
}
WId Session::windowId() const
......
......@@ -96,8 +96,10 @@ public:
* Calling openTeletype() while a session is running has no effect.
*
* @param fd The file descriptor of the pseudo-teletype master (See KPtyProcess::KPtyProcess())
* @param runShell When true, runs the teletype in a shell session environment.
* When false, the session is not run, so that the KPtyProcess can be standalone.
*/
void openTeletype(int fd);
void openTeletype(int fd, bool runShell);
/**
* Returns true if the session is currently running. This will be true
......
......@@ -92,8 +92,9 @@ void PartTest::testFd()
int fd = ptyProcess.pty()->masterFd();
// connect to an existing pty. The 2nd argument of openTeletype is optional, to run without shell
bool result = QMetaObject::invokeMethod(terminalPart, "openTeletype",
Qt::DirectConnection, Q_ARG(int, fd));
Qt::DirectConnection, Q_ARG(int, fd), Q_ARG(bool, false));
QVERIFY(result);
// suspend the KPtyDevice so that the embedded terminal gets a chance to
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment