// 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 "id.h" #include #include namespace Utils { class ProcessInterface; template class Hook { public: using Callback = std::function; 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)...); } private: Callback m_callback; }; namespace Terminal { struct HooksPrivate; enum class ExitBehavior { Close, Restart, Keep }; struct OpenTerminalParameters { std::optional shellCommand; std::optional workingDirectory; std::optional environment; ExitBehavior m_exitBehavior{ExitBehavior::Close}; std::optional identifier{std::nullopt}; }; struct NameAndCommandLine { QString name; CommandLine commandLine; }; QTCREATOR_UTILS_EXPORT FilePath defaultShellForDevice(const FilePath &deviceRoot); class QTCREATOR_UTILS_EXPORT Hooks { public: using OpenTerminalHook = Hook; using CreateTerminalProcessInterfaceHook = Hook; using GetTerminalCommandsForDevicesHook = Hook>; public: static Hooks &instance(); ~Hooks(); OpenTerminalHook &openTerminalHook(); CreateTerminalProcessInterfaceHook &createTerminalProcessInterfaceHook(); GetTerminalCommandsForDevicesHook &getTerminalCommandsForDevicesHook(); private: Hooks(); std::unique_ptr d; }; } // namespace Terminal } // namespace Utils