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 
7 namespace openmsx {
8 
10  : Command(controller, "message")
11 {
12 }
13 
14 static CliComm::LogLevel getLevel(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 
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  // fall-through
34  case 2:
35  cliComm.log(level, tokens[1].getString());
36  break;
37  }
38 }
39 
40 std::string MessageCommand::help(const std::vector<std::string>& /*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 
49 void MessageCommand::tabCompletion(std::vector<std::string>& tokens) const
50 {
51  if (tokens.size() == 3) {
53  }
54 }
55 
56 } // namespace openmsx
auto xrange(T e)
Definition: xrange.hh:170
Definition: span.hh:34
void checkNumArgs(span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
Definition: Completer.cc:180
std::string help(const std::vector< std::string > &tokens) const override
Print help for this command.
MessageCommand(CommandController &controller)
static span< const char *const > getLevelStrings()
Definition: CliComm.hh:78
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void tabCompletion(std::vector< std::string > &tokens) const override
Attempt tab completion for this command.
static void completeString(std::vector< std::string > &tokens, ITER begin, ITER end, bool caseSensitive=true)
Definition: Completer.hh:124
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
void execute(span< const TclObject > tokens, TclObject &result) override
Execute this command.
CliComm & getCliComm() const
Definition: Command.cc:46