openMSX
GlobalCommandController.hh
Go to the documentation of this file.
1#ifndef GLOBALCOMMANDCONTROLLER_HH
2#define GLOBALCOMMANDCONTROLLER_HH
3
5#include "Command.hh"
6#include "Interpreter.hh"
7#include "InfoCommand.hh"
8#include "InfoTopic.hh"
9#include "HotKey.hh"
10#include "SettingsConfig.hh"
11#include "RomInfoTopic.hh"
12#include "TclObject.hh"
13#include "hash_map.hh"
14#include "xxhash.hh"
15#include <string>
16#include <vector>
17#include <memory>
18
19namespace openmsx {
20
21class EventDistributor;
22class Reactor;
23class GlobalCliComm;
24class ProxyCmd;
25class ProxySetting;
26
28{
29protected:
31
32#ifdef DEBUG
34#endif
36};
37
39 , public CommandController
40{
41public:
44
46 GlobalCliComm& cliComm,
47 Reactor& reactor);
49
50 [[nodiscard]] InfoCommand& getOpenMSXInfoCommand() { return openMSXInfoCommand; }
51
55 void source(const std::string& script);
56
57 void registerProxyCommand(std::string_view name);
58 void unregisterProxyCommand(std::string_view name);
59
62
63 // CommandController
64 void registerCompleter(CommandCompleter& completer,
65 std::string_view str) override;
67 std::string_view str) override;
68 void registerCommand(Command& command,
69 zstring_view str) override;
70 void unregisterCommand(Command& command,
71 std::string_view str) override;
73 CliConnection* connection = nullptr) override;
74 void registerSetting(Setting& setting) override;
75 void unregisterSetting(Setting& setting) override;
76 [[nodiscard]] CliComm& getCliComm() override;
77 [[nodiscard]] Interpreter& getInterpreter() override;
78
82 [[nodiscard]] std::string tabCompletion(std::string_view command);
83
88 [[nodiscard]] bool isComplete(zstring_view command);
89
90 [[nodiscard]] SettingsConfig& getSettingsConfig() { return settingsConfig; }
91 [[nodiscard]] SettingsManager& getSettingsManager() { return settingsConfig.getSettingsManager(); }
92 [[nodiscard]] CliConnection* getConnection() const { return connection; }
93
94private:
95 void tabCompletion(std::vector<std::string>& tokens);
96
97 using ProxySettings =
98 std::vector<std::pair<std::unique_ptr<ProxySetting>, unsigned>>;
99 ProxySettings::iterator findProxySetting(std::string_view name);
100
101 GlobalCliComm& cliComm;
102 CliConnection* connection = nullptr;
103
104 Reactor& reactor;
105
106 Interpreter interpreter;
107 InfoCommand openMSXInfoCommand;
108 HotKey hotKey;
109 SettingsConfig settingsConfig;
110
111 struct HelpCmd final : Command {
112 explicit HelpCmd(GlobalCommandController& controller);
113 void execute(std::span<const TclObject> tokens, TclObject& result) override;
114 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
115 void tabCompletion(std::vector<std::string>& tokens) const override;
116 } helpCmd;
117
118 struct TabCompletionCmd final : Command {
119 explicit TabCompletionCmd(GlobalCommandController& controller);
120 void execute(std::span<const TclObject> tokens, TclObject& result) override;
121 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
122 } tabCompletionCmd;
123
124 struct UpdateCmd final : Command {
125 explicit UpdateCmd(CommandController& commandController);
126 void execute(std::span<const TclObject> tokens, TclObject& result) override;
127 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
128 void tabCompletion(std::vector<std::string>& tokens) const override;
129 private:
130 CliConnection& getConnection();
131 } updateCmd;
132
133 struct PlatformInfo final : InfoTopic {
134 explicit PlatformInfo(InfoCommand& openMSXInfoCommand);
135 void execute(std::span<const TclObject> tokens,
136 TclObject& result) const override;
137 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
138 } platformInfo;
139
140 struct VersionInfo final : InfoTopic {
141 explicit VersionInfo(InfoCommand& openMSXInfoCommand);
142 void execute(std::span<const TclObject> tokens,
143 TclObject& result) const override;
144 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
145 } versionInfo;
146
147 RomInfoTopic romInfoTopic;
148
149 struct NameFromProxy {
150 template<typename Pair>
151 [[nodiscard]] const std::string& operator()(const Pair& p) const {
152 return p.second->getName();
153 }
154 };
156 ProxySettings proxySettings;
157};
158
159} // namespace openmsx
160
161#endif
BaseSetting * setting
Definition: Interpreter.cc:28
hash_map< std::string, CommandCompleter *, XXHasher > commandCompleters
GlobalCommandController(const GlobalCommandController &)=delete
void registerSetting(Setting &setting) override
TODO.
std::string tabCompletion(std::string_view command)
Complete the given command.
void registerProxyCommand(std::string_view name)
void unregisterProxyCommand(std::string_view name)
void registerCommand(Command &command, zstring_view str) override
(Un)register a command
void registerCompleter(CommandCompleter &completer, std::string_view str) override
(Un)register a command completer, used to complete build-in Tcl cmds
TclObject executeCommand(zstring_view command, CliConnection *connection=nullptr) override
Execute the given command.
void unregisterSetting(Setting &setting) override
GlobalCommandController & operator=(const GlobalCommandController &)=delete
void unregisterCompleter(CommandCompleter &completer, std::string_view str) override
void unregisterCommand(Command &command, std::string_view str) override
bool isComplete(zstring_view command)
Returns true iff the command is complete (all braces, quotes etc.
void source(const std::string &script)
Executes all defined auto commands.
Contains the main loop of openMSX.
Definition: Reactor.hh:68
SettingsManager & getSettingsManager()
Manages all settings.
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
Definition: zstring_view.hh:22
This file implemented 3 utility functions:
Definition: Autofire.cc:9