@@ -21,6 +21,7 @@ Author: Daniel Kroening, kroening@kroening.com
2121
2222ui_message_handlert::ui_message_handlert ()
2323 : _ui(uit::PLAIN),
24+ always_flush(false ),
2425 time(timestampert::make(timestampert::clockt::NONE)),
2526 out(std::cout),
2627 json_stream(nullptr )
@@ -30,8 +31,10 @@ ui_message_handlert::ui_message_handlert()
3031ui_message_handlert::ui_message_handlert (
3132 uit __ui,
3233 const std::string &program,
34+ bool always_flush,
3335 timestampert::clockt clock_type)
3436 : _ui(__ui),
37+ always_flush(always_flush),
3538 time(timestampert::make(clock_type)),
3639 out(std::cout),
3740 json_stream(nullptr )
@@ -79,6 +82,7 @@ ui_message_handlert::ui_message_handlert(
7982 ? uit::JSON_UI
8083 : uit::PLAIN,
8184 program,
85+ cmdline.isset(" flush" ),
8286 cmdline.isset(" timestamp" )
8387 ? cmdline.get_value(" timestamp" ) == "monotonic"
8488 ? timestampert::clockt::MONOTONIC
@@ -130,11 +134,13 @@ void ui_message_handlert::print(
130134 {
131135 case uit::PLAIN:
132136 {
133- console_message_handlert console_message_handler;
137+ console_message_handlert console_message_handler (always_flush) ;
134138 std::stringstream ss;
135139 const std::string timestamp = time->stamp ();
136140 ss << timestamp << (timestamp.empty () ? " " : " " ) << message;
137141 console_message_handler.print (level, ss.str ());
142+ if (always_flush)
143+ console_message_handler.flush (level);
138144 }
139145 break ;
140146
@@ -274,6 +280,8 @@ void ui_message_handlert::xml_ui_msg(
274280
275281 out << result;
276282 out << ' \n ' ;
283+ if (always_flush)
284+ flush (1 );
277285}
278286
279287void ui_message_handlert::json_ui_msg (
@@ -299,6 +307,8 @@ void ui_message_handlert::json_ui_msg(
299307 // The first entry is generated in the constructor and does not have
300308 // a trailing comma.
301309 std::cout << " ,\n " << result;
310+ if (always_flush)
311+ flush (1 );
302312}
303313
304314void ui_message_handlert::flush (unsigned level)
@@ -307,7 +317,7 @@ void ui_message_handlert::flush(unsigned level)
307317 {
308318 case uit::PLAIN:
309319 {
310- console_message_handlert console_message_handler;
320+ console_message_handlert console_message_handler (always_flush) ;
311321 console_message_handler.flush (level);
312322 }
313323 break ;
0 commit comments