From b8c5a312e632c1b83324d9f38a923863ae985dfb Mon Sep 17 00:00:00 2001 From: Twan van Laarhoven Date: Mon, 20 Apr 2020 23:04:38 +0200 Subject: [PATCH] Move print_pending_errors to text_io_handler --- src/cli/cli_main.cpp | 12 ++---------- src/cli/cli_main.hpp | 1 - src/cli/text_io_handler.cpp | 18 ++++++++++++++++-- src/cli/text_io_handler.hpp | 3 ++- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/cli/cli_main.cpp b/src/cli/cli_main.cpp index 7a5a117a..4e687e35 100644 --- a/src/cli/cli_main.cpp +++ b/src/cli/cli_main.cpp @@ -99,7 +99,7 @@ bool run_script_file(String const& filename) { void CLISetInterface::run() { // show welcome logo if (!quiet) showWelcome(); - print_pending_errors(); + cli.print_pending_errors(); // loop running = true; while (running) { @@ -112,7 +112,7 @@ void CLISetInterface::run() { String command = cli.getLine(); if (command.empty() && !cli.canGetLine()) break; handleCommand(command); - print_pending_errors(); + cli.print_pending_errors(); cli.flush(); cli.flushRaw(); } @@ -260,11 +260,3 @@ 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); - } -} diff --git a/src/cli/cli_main.hpp b/src/cli/cli_main.hpp index b4e1d340..8dfc11b0 100644 --- a/src/cli/cli_main.hpp +++ b/src/cli/cli_main.hpp @@ -35,7 +35,6 @@ private: #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(); diff --git a/src/cli/text_io_handler.cpp b/src/cli/text_io_handler.cpp index 465cc1dd..00df054c 100644 --- a/src/cli/text_io_handler.cpp +++ b/src/cli/text_io_handler.cpp @@ -152,9 +152,9 @@ void TextIOHandler::flushRaw() { if (!buffer.empty()) { #ifdef UNICODE wxCharBuffer buf = buffer.mb_str(wxConvUTF8); - fputs(buf,stdout); + fputs(buf,stream); #else - fputs(buffer.c_str(),stdout); + fputs(buffer.c_str(), stream); #endif } fflush(stdout); @@ -178,6 +178,20 @@ void TextIOHandler::show_message(MessageType type, String const& message) { if (raw_mode) raw_mode_status = max(raw_mode_status, type == MESSAGE_WARNING ? 1 : 2); } +void TextIOHandler::print_pending_errors() { + MessageType type; + String msg; + while (get_queued_message(type, msg)) { + if (haveConsole()) { + show_message(type, msg); + flush(); + } else { + // no console, use a messagebox instead + wxMessageBox(msg, wxMessageBoxCaptionStr, type == MESSAGE_INFO ? wxICON_INFORMATION : type == MESSAGE_WARNING ? wxICON_WARNING : wxICON_ERROR); + } + } +} + bool TextIOHandler::shown_errors() const { return encountered_errors; } diff --git a/src/cli/text_io_handler.hpp b/src/cli/text_io_handler.hpp index d60264db..6197fa65 100644 --- a/src/cli/text_io_handler.hpp +++ b/src/cli/text_io_handler.hpp @@ -38,6 +38,7 @@ public: /// Show an error or warning message void show_message(MessageType type, String const& message); + void print_pending_errors(); bool shown_errors() const; /// Enable raw mode @@ -49,7 +50,7 @@ public: private: bool have_console; bool escapes; - FILE* stream; + FILE* stream; ///< Output stream String buffer; ///< Buffer when not writing to console bool raw_mode; int raw_mode_status;