openMSX
MessageCommand.cc
Go to the documentation of this file.
1 #include "MessageCommand.hh"
2 #include "CommandException.hh"
3 #include "CliComm.hh"
4 #include "xrange.hh"
5 
6 namespace openmsx {
7 
9  : Command(controller, "message")
10 {
11 }
12 
13 static CliComm::LogLevel getLevel(const std::string& level)
14 {
15  auto levels = CliComm::getLevelStrings();
16  for (auto i : xrange(levels.size())) {
17  if (level == levels[i]) {
18  return static_cast<CliComm::LogLevel>(i);
19  }
20  }
21  throw CommandException("Unknown level string: " + level);
22 }
23 
24 std::string MessageCommand::execute(const std::vector<std::string>& tokens)
25 {
26  CliComm& cliComm = getCliComm();
28  switch (tokens.size()) {
29  case 3:
30  level = getLevel(tokens[2]);
31  // fall-through
32  case 2:
33  cliComm.log(level, tokens[1]);
34  break;
35  default:
36  throw SyntaxError();
37  }
38  return "";
39 }
40 
41 std::string MessageCommand::help(const std::vector<std::string>& /*tokens*/) const
42 {
43  return "message <text> [<level>]\n"
44  "Print a message. (By default) this message will be shown in "
45  "a colored box at the top of the screen. It's possible to "
46  "specify a level for the message (e.g. 'info', 'warning' or "
47  "'error').";
48 }
49 
50 void MessageCommand::tabCompletion(std::vector<std::string>& tokens) const
51 {
52  if (tokens.size() == 3) {
54  }
55 }
56 
57 } // namespace openmsx