From 2656d37391527cd4fdc18b428a14f23d3b00f704 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Kupec?= Date: Thu, 7 Jan 2010 14:08:43 +0100 Subject: [PATCH] Avoid overwriting progress lines with other messages (bnc #495977) --- src/output/OutNormal.cc | 30 ++++++++++++++++++++++++++++++ src/output/OutNormal.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/src/output/OutNormal.cc b/src/output/OutNormal.cc index bf0c3ce..edf3d18 100644 --- a/src/output/OutNormal.cc +++ b/src/output/OutNormal.cc @@ -58,12 +58,16 @@ void OutNormal::info(const std::string & msg, Verbosity verbosity, Type mask) if (infoWarningFilter(verbosity, mask)) return; + if (!_newline) + cout << endl; + if (verbosity == Out::QUIET) print_color(msg, COLOR_CONTEXT_RESULT); else print_color(msg, COLOR_CONTEXT_MSG_STATUS); cout << endl; + _newline = true; } void OutNormal::warning(const std::string & msg, Verbosity verbosity, Type mask) @@ -71,16 +75,24 @@ void OutNormal::warning(const std::string & msg, Verbosity verbosity, Type mask) if (infoWarningFilter(verbosity, mask)) return; + if (!_newline) + cout << endl; + print_color(_("Warning: "), COLOR_CONTEXT_MSG_WARNING); cout << msg << endl; + _newline = true; } void OutNormal::error(const std::string & problem_desc, const std::string & hint) { + if (!_newline) + cout << endl; + fprint_color(cerr, problem_desc, COLOR_CONTEXT_MSG_ERROR); if (!hint.empty() && this->verbosity() > Out::QUIET) cerr << endl << hint; cerr << endl; + _newline = true; } // ---------------------------------------------------------------------------- @@ -89,6 +101,9 @@ void OutNormal::error(const zypp::Exception & e, const string & problem_desc, const string & hint) { + if (!_newline) + cout << endl; + // problem fprint_color(cerr, problem_desc, COLOR_CONTEXT_MSG_ERROR); cerr << endl; @@ -99,6 +114,8 @@ void OutNormal::error(const zypp::Exception & e, // hint if (!hint.empty() && this->verbosity() > Out::QUIET) cerr << hint << endl; + + _newline = true; } // ---------------------------------------------------------------------------- @@ -153,6 +170,8 @@ void OutNormal::progressStart(const std::string & id, display_tick(id, label); else display_progress(id, label, 0); + + _newline = false; } void OutNormal::progress(const std::string & id, const string & label, int value) @@ -164,6 +183,8 @@ void OutNormal::progress(const std::string & id, const string & label, int value display_progress(id, label, value); else display_tick(id, label); + + _newline = false; } void OutNormal::progressEnd(const std::string & id, const string & label, bool error) @@ -188,6 +209,7 @@ void OutNormal::progressEnd(const std::string & id, const string & label, bool e cout << COLOR_RESET; cout << endl << std::flush; + _newline = true; } // progress with download rate @@ -209,6 +231,7 @@ void OutNormal::dwnldProgressStart(const zypp::Url & uri) cout << " [" ; cout << std::flush; + _newline = false; } void OutNormal::dwnldProgress(const zypp::Url & uri, @@ -241,6 +264,7 @@ void OutNormal::dwnldProgress(const zypp::Url & uri, } cout << std::flush; + _newline = false; } void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error) @@ -275,6 +299,7 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error) cout << COLOR_RESET; cout << endl << std::flush; + _newline = true; } void OutNormal::prompt(PromptId id, @@ -282,6 +307,9 @@ void OutNormal::prompt(PromptId id, const PromptOptions & poptions, const std::string & startdesc) { + if (!_newline) + cout << endl; + if (startdesc.empty()) { if (_isatty) @@ -293,6 +321,7 @@ void OutNormal::prompt(PromptId id, if (!poptions.empty()) cout << " " << poptions.optionString(); cout << ": " << std::flush; + _newline = false; } void OutNormal::promptHelp(const PromptOptions & poptions) @@ -319,4 +348,5 @@ void OutNormal::promptHelp(const PromptOptions & poptions) } cout << endl << poptions.optionString() << ": " << std::flush; + _newline = false; } diff --git a/src/output/OutNormal.h b/src/output/OutNormal.h index f7186ff..8ac75cd 100644 --- a/src/output/OutNormal.h +++ b/src/output/OutNormal.h @@ -75,8 +75,12 @@ protected: private: bool infoWarningFilter(Verbosity verbosity, Type mask); + bool _use_colors; bool _isatty; + /* Newline flag. false if the last output did not end with new line character + * (like in a self-overwriting progress line), false otherwise. */ + bool _newline; }; #endif /*OUTNORMAL_H_*/ -- 2.7.4