openMSX
MessageCommand.cc
Go to the documentation of this file.
1#include "MessageCommand.hh"
2#include "CommandException.hh"
3#include "CliComm.hh"
4#include "TclObject.hh"
5#include "xrange.hh"
6
7namespace openmsx {
8
10 : Command(controller, "message")
11{
12}
13
14[[nodiscard]] static CliComm::LogLevel getLevel(std::string_view level)
15{
16 auto levels = CliComm::getLevelStrings();
17 for (auto i : xrange(levels.size())) {
18 if (level == levels[i]) {
19 return static_cast<CliComm::LogLevel>(i);
20 }
21 }
22 throw CommandException("Unknown level string: ", level);
23}
24
25void MessageCommand::execute(std::span<const TclObject> tokens, TclObject& /*result*/)
26{
27 checkNumArgs(tokens, Between{2, 3}, "string ?level?");
28 CliComm& cliComm = getCliComm();
30 switch (tokens.size()) {
31 case 3:
32 level = getLevel(tokens[2].getString());
33 [[fallthrough]];
34 case 2:
35 cliComm.log(level, tokens[1].getString());
36 break;
37 }
38}
39
40std::string MessageCommand::help(std::span<const TclObject> /*tokens*/) const
41{
42 return "message <text> [<level>]\n"
43 "Print a message. (By default) this message will be shown in "
44 "a colored box at the top of the screen. It's possible to "
45 "specify a level for the message (e.g. 'info', 'warning' or "
46 "'error').";
47}
48
49void MessageCommand::tabCompletion(std::vector<std::string>& tokens) const
50{
51 if (tokens.size() == 3) {
53 }
54}
55
56} // namespace openmsx
static std::span< const std::string_view, NUM_LEVELS > getLevelStrings()
Definition: CliComm.hh:88
CliComm & getCliComm() const
Definition: Command.cc:43
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
Definition: Completer.hh:133
void checkNumArgs(std::span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
Definition: Completer.cc:177
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
MessageCommand(CommandController &controller)
void execute(std::span< const TclObject > tokens, TclObject &result) override
Execute this command.
std::string help(std::span< const TclObject > tokens) const override
Print help for this command.
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr auto xrange(T e)
Definition: xrange.hh:133