forked from qt-creator/qt-creator
Terminal: Add Terminal plugin
Adds a new Terminal plugin that provides a Terminal pane inside Qt Creator. Fixes: QTCREATORBUG-8511 Change-Id: I7eacb3efa2463d7df9f383ae3fc33254fb9019a9 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
70
src/libs/utils/terminalhooks.h
Normal file
70
src/libs/utils/terminalhooks.h
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "commandline.h"
|
||||
#include "environment.h"
|
||||
#include "filepath.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Utils {
|
||||
class ProcessInterface;
|
||||
|
||||
template<typename R, typename... Params>
|
||||
class Hook
|
||||
{
|
||||
public:
|
||||
using Callback = std::function<R(Params...)>;
|
||||
|
||||
public:
|
||||
Hook() = delete;
|
||||
Hook(const Hook &other) = delete;
|
||||
Hook(Hook &&other) = delete;
|
||||
Hook &operator=(const Hook &other) = delete;
|
||||
Hook &operator=(Hook &&other) = delete;
|
||||
|
||||
explicit Hook(Callback defaultCallback) { set(defaultCallback); }
|
||||
|
||||
void set(Callback cb) { m_callback = cb; }
|
||||
R operator()(Params &&...params) { return m_callback(std::forward<Params>(params)...); }
|
||||
|
||||
private:
|
||||
Callback m_callback;
|
||||
};
|
||||
|
||||
namespace Terminal {
|
||||
struct HooksPrivate;
|
||||
|
||||
enum class ExitBehavior { Close, Restart, Keep };
|
||||
|
||||
struct OpenTerminalParameters
|
||||
{
|
||||
std::optional<CommandLine> shellCommand;
|
||||
std::optional<FilePath> workingDirectory;
|
||||
std::optional<Environment> environment;
|
||||
ExitBehavior m_exitBehavior{ExitBehavior::Close};
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Hooks
|
||||
{
|
||||
public:
|
||||
using OpenTerminalHook = Hook<void, const OpenTerminalParameters &>;
|
||||
using CreateTerminalProcessInterfaceHook = Hook<ProcessInterface *>;
|
||||
|
||||
public:
|
||||
static Hooks &instance();
|
||||
|
||||
OpenTerminalHook &openTerminalHook();
|
||||
CreateTerminalProcessInterfaceHook &createTerminalProcessInterfaceHook();
|
||||
|
||||
~Hooks();
|
||||
private:
|
||||
Hooks();
|
||||
std::unique_ptr<HooksPrivate> d;
|
||||
};
|
||||
|
||||
} // namespace Terminal
|
||||
} // namespace Utils
|
||||
Reference in New Issue
Block a user