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