9 void Command_Interpreter::after_command
14 const std::string &line,
15 const Exception *exception
20 std::ostringstream error;
21 error << exception->what();
22 error <<
"\nLine " << line_number <<
": " << line <<
'\n';
25 throw Exception(error.str());
27 out <<
"Exception caught: " << error.str();
30 out <<
"OK: " << line <<
'\n';
37 const std::string &command,
38 std::istream ¶meters,
43 if (command.empty() || command[0] ==
'#')
46 else if (command ==
"about")
50 else if (command ==
"echo")
52 std::string parameter;
53 parameters >> parameter;
55 if (parameter ==
"on")
57 else if (parameter ==
"off")
60 else if (command ==
"prompt")
62 std::string parameter;
63 parameters >> parameter;
65 if (parameter ==
"on")
67 else if (parameter ==
"off")
70 else if (command ==
"help")
86 else if (command ==
"quit")
88 else if (command ==
"abort")
91 return Status::not_found;
107 processors.emplace_back(processor);
119 rethrow = parent->rethrow;
120 prompt = parent->prompt;
137 parent->write_prompt(out);
150 int64_t line_number = 0;
159 if (!std::getline(in, line))
163 std::istringstream iss(line);
175 for (
const auto &processor: processors)
178 processor.get().process_command(command, iss, in, out);
203 "Unknown command. For a list of available commands, try \"help\"."
207 after_command(out, line_number, line,
nullptr);
212 catch (
const Exception &e)
214 after_command(out, line_number, line, &e);
219 throw Exception(
"aborted");
void set_parent(const Command_Interpreter *new_parent)
void main_loop(std::istream &in, std::ostream &out)
void write_whole_prompt(std::ostream &out) const
Status process_command(const std::string &command, std::istream ¶meters, std::istream &in, std::ostream &out) override
void add_processor(Command_Processor &processor)
virtual void write_prompt(std::ostream &out) const
void about_joedb(std::ostream &out)