diff options
author | Marcus Tillmanns <[email protected]> | 2023-03-07 17:55:38 +0100 |
---|---|---|
committer | Marcus Tillmanns <[email protected]> | 2023-03-20 10:03:23 +0000 |
commit | 0870f2583bbc659df00ff65bf51918b940221665 (patch) | |
tree | da42641235dc92c9fb251c5699faa3d83ac7f450 /src/libs/utils/terminalhooks.cpp | |
parent | 2d2eef1c2cd3e55e8d1c37b0dff739f29d06f5ca (diff) |
Terminal: Enable TerminalProcessInterface
Adds a new helper app "process_stub" that replaces the previous.
"process_stub_unix/win". The purpose was and is to allow processes
to be "injected" into other hosts apps like terminals while still
being able to control and debug them.
A new base class called "TerminalInterface" is used for both the new
Terminal plugin and the legacy TerminalProcess implementation.
Fixes: QTCREATORBUG-16364
Change-Id: If21273fe53ad545d1a768c17c83db4bf2fd85395
Reviewed-by: Christian Stenger <[email protected]>
Reviewed-by: Jarek Kobus <[email protected]>
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/libs/utils/terminalhooks.cpp')
-rw-r--r-- | src/libs/utils/terminalhooks.cpp | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/src/libs/utils/terminalhooks.cpp b/src/libs/utils/terminalhooks.cpp index f4a5944dbdc..8187229cbf5 100644 --- a/src/libs/utils/terminalhooks.cpp +++ b/src/libs/utils/terminalhooks.cpp @@ -3,8 +3,12 @@ #include "terminalhooks.h" +#include "terminalinterface.h" #include "filepath.h" -#include "terminalprocess_p.h" +#include "qtcprocess.h" +#include "terminalcommand.h" + +#include <QTemporaryFile> namespace Utils::Terminal { @@ -26,6 +30,61 @@ FilePath defaultShellForDevice(const FilePath &deviceRoot) return shell.onDevice(deviceRoot); } +class ExternalTerminalProcessImpl final : public TerminalInterface +{ + class ProcessStubCreator : public StubCreator + { + public: + ProcessStubCreator(ExternalTerminalProcessImpl *interface) + : m_interface(interface) + {} + + void startStubProcess(const CommandLine &cmd, const ProcessSetupData &) override + { + if (HostOsInfo::isWindowsHost()) { + m_terminalProcess.setCommand(cmd); + QObject::connect(&m_terminalProcess, &QtcProcess::done, this, [this] { + m_interface->onStubExited(); + }); + m_terminalProcess.start(); + } else if (HostOsInfo::isMacHost()) { + QTemporaryFile f; + f.setAutoRemove(false); + f.open(); + f.setPermissions(QFile::ExeUser | QFile::ReadUser | QFile::WriteUser); + f.write("#!/bin/sh\n"); + f.write(QString("exec '%1' %2\n") + .arg(cmd.executable().nativePath()) + .arg(cmd.arguments()) + .toUtf8()); + f.close(); + + const QString path = f.fileName(); + const QString exe + = QString("tell app \"Terminal\" to do script \"'%1'; rm -f '%1'; exit\"") + .arg(path); + + m_terminalProcess.setCommand({"osascript", {"-e", exe}}); + m_terminalProcess.runBlocking(); + } else { + const TerminalCommand terminal = TerminalCommand::terminalEmulator(); + + CommandLine cmdLine = {terminal.command, {terminal.executeArgs}}; + cmdLine.addCommandLineAsArgs(cmd, CommandLine::Raw); + + m_terminalProcess.setCommand(cmdLine); + m_terminalProcess.start(); + } + } + + ExternalTerminalProcessImpl *m_interface; + QtcProcess m_terminalProcess; + }; + +public: + ExternalTerminalProcessImpl() { setStubCreator(new ProcessStubCreator(this)); } +}; + struct HooksPrivate { HooksPrivate() @@ -34,9 +93,8 @@ struct HooksPrivate FilePath{}), parameters.environment.value_or(Environment{})); }) - , m_createTerminalProcessInterfaceHook( - []() -> ProcessInterface * { return new Internal::TerminalImpl(); }) - , m_getTerminalCommandsForDevicesHook([]() -> QList<NameAndCommandLine> { return {}; }) + , m_createTerminalProcessInterfaceHook([] { return new ExternalTerminalProcessImpl(); }) + , m_getTerminalCommandsForDevicesHook([] { return QList<NameAndCommandLine>{}; }) {} Hooks::OpenTerminalHook m_openTerminalHook; |