* Added console panel for evaluating scripts and showing error messages.

* Rewrite of error queue code: errors are now pulled, instead of being turned into messageboxes automatically.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1629 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2011-01-21 13:26:03 +00:00
parent 4079bc26b8
commit bd55326c7d
37 changed files with 1288 additions and 797 deletions
+17 -8
View File
@@ -75,7 +75,7 @@ void CLISetInterface::setExportInfoCwd() {
void CLISetInterface::run() {
// show welcome logo
if (!quiet) showWelcome();
handle_pending_errors();
print_pending_errors();
// loop
running = true;
while (running) {
@@ -88,6 +88,7 @@ void CLISetInterface::run() {
String command = cli.getLine();
if (command.empty() && !cli.canGetLine()) break;
handleCommand(command);
print_pending_errors();
cli.flush();
cli.flushRaw();
}
@@ -134,7 +135,7 @@ void CLISetInterface::handleCommand(const String& command) {
showUsage();
} else if (before == _(":l") || before == _(":load")) {
if (arg.empty()) {
cli.showError(_("Give a filename to open."));
cli.show_message(MESSAGE_ERROR,_("Give a filename to open."));
} else {
setSet(import_set(arg));
}
@@ -154,10 +155,10 @@ void CLISetInterface::handleCommand(const String& command) {
}
} else if (before == _(":c") || before == _(":cd")) {
if (arg.empty()) {
cli.showError(_("Give a new working directory."));
cli.show_message(MESSAGE_ERROR,_("Give a new working directory."));
} else {
if (!wxSetWorkingDirectory(arg)) {
cli.showError(_("Can't change working directory to ")+arg);
cli.show_message(MESSAGE_ERROR,_("Can't change working directory to ")+arg);
} else {
setExportInfoCwd();
}
@@ -166,7 +167,7 @@ void CLISetInterface::handleCommand(const String& command) {
cli << ei.directory_absolute << ENDL;
} else if (before == _(":!")) {
if (arg.empty()) {
cli.showError(_("Give a shell command to execute."));
cli.show_message(MESSAGE_ERROR,_("Give a shell command to execute."));
} else {
#ifdef UNICODE
#ifdef __WXMSW__
@@ -190,7 +191,7 @@ void CLISetInterface::handleCommand(const String& command) {
}
#endif
} else {
cli.showError(_("Unknown command, type :help for help."));
cli.show_message(MESSAGE_ERROR,_("Unknown command, type :help for help."));
}
} else if (command == _("exit") || command == _("quit")) {
cli << _("Use :quit to quit\n");
@@ -201,7 +202,7 @@ void CLISetInterface::handleCommand(const String& command) {
vector<ScriptParseError> errors;
ScriptP script = parse(command,nullptr,false,errors);
if (!errors.empty()) {
FOR_EACH(error,errors) cli.showError(error.what());
FOR_EACH(error,errors) cli.show_message(MESSAGE_ERROR,error.what());
return;
}
// execute command
@@ -212,7 +213,7 @@ void CLISetInterface::handleCommand(const String& command) {
cli << result->toCode() << ENDL;
}
} catch (const Error& e) {
cli.showError(e.what());
cli.show_message(MESSAGE_ERROR,e.what());
}
}
@@ -235,3 +236,11 @@ void CLISetInterface::handleCommand(const String& command) {
}
}
#endif
void CLISetInterface::print_pending_errors() {
MessageType type;
String msg;
while (get_queued_message(type,msg)) {
cli.show_message(type,msg);
}
}
+1
View File
@@ -36,6 +36,7 @@ class CLISetInterface : public SetView {
#if USE_SCRIPT_PROFILING
void showProfilingStats(const FunctionProfile& parent, int level = 0);
#endif
void print_pending_errors();
/// our own context, when no set is loaded
Context& getContext();
+22 -15
View File
@@ -35,7 +35,7 @@ TextIOHandler cli;
void TextIOHandler::init() {
bool have_stderr;
#ifdef __WXMSW__
#if defined(__WXMSW__)
have_console = false;
escapes = false;
// Detect whether to use console output
@@ -51,9 +51,20 @@ void TextIOHandler::init() {
}
}
#else
// always use console on *nix (?)
have_console = true;
have_stderr = true;
// TODO: detect console on linux?
have_console = false;
have_stderr = false;
// Use console mode if one of the cli flags is passed
static const Char* redirect_flags[] = {_("-?"),_("--help"),_("-v"),_("--version"),_("--cli"),_("-c"),_("--export"),_("--create-installer")};
for (int i = 1 ; i < wxTheApp->argc ; ++i) {
for (int j = 0 ; j < sizeof(redirect_flags)/sizeof(redirect_flags[0]) ; ++j) {
if (String(wxTheApp->argv[i]) == redirect_flags[j]) {
have_console = true;
have_stderr = true;
break;
}
}
}
escapes = true; // TODO: detect output redirection
#endif
// write to standard output
@@ -154,18 +165,14 @@ void TextIOHandler::flushRaw() {
// ----------------------------------------------------------------------------- : Errors
void TextIOHandler::showError(const String& message) {
void TextIOHandler::show_message(MessageType type, String const& message) {
stream = stdout;
*this << RED << _("ERROR: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
if (type == MESSAGE_WARNING) {
*this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
} else {
*this << RED << _("ERROR: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
}
flush();
stream = stdout;
if (raw_mode) raw_mode_status = max(raw_mode_status, 2);
}
void TextIOHandler::showWarning(const String& message) {
stream = stdout;
*this << YELLOW << _("WARNING: ") << NORMAL << replace_all(message,_("\n"),_("\n ")) << ENDL;
flush();
stream = stdout;
if (raw_mode) raw_mode_status = max(raw_mode_status, 1);
if (raw_mode) raw_mode_status = max(raw_mode_status, type == MESSAGE_WARNING ? 1 : 2);
}
+2 -4
View File
@@ -36,10 +36,8 @@ class TextIOHandler {
/// Flush output
void flush();
/// Show an error message
void showError(const String& message);
/// Show a warning message
void showWarning(const String& message);
/// Show an error or warning message
void show_message(MessageType type, String const& message);
/// Enable raw mode
void enableRaw();