From 8008866b874421e2c9b374a907b71bbd500d682b Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Tue, 22 Apr 2008 13:58:56 +0000 Subject: [PATCH] make different output to terminal and rest --- src/output/OutNormal.cc | 69 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/src/output/OutNormal.cc b/src/output/OutNormal.cc index 8d051f2..cec650e 100644 --- a/src/output/OutNormal.cc +++ b/src/output/OutNormal.cc @@ -1,6 +1,8 @@ #include #include +#include + #include "zypp/Pathname.h" #include "zypp/ByteCount.h" // for download progress reporting #include "zypp/base/String.h" // for toUpper() @@ -81,11 +83,16 @@ static void display_progress ( const std::string & id, const string & s, int per { static AliveCursor cursor; - cout << CLEARLN << cursor++ << " " << s; - // dont display percents if invalid - if (percent >= 0 && percent <= 100) - cout << " [" << percent << "%]"; - cout << std::flush; + if (isatty(1)) + { + cout << CLEARLN << cursor++ << " " << s; + // dont display percents if invalid + if (percent >= 0 && percent <= 100) + cout << " [" << percent << "%]"; + cout << std::flush; + } + else + cout << '.' << std::flush; } // ---------------------------------------------------------------------------- @@ -94,9 +101,16 @@ static void display_tick ( const std::string & id, const string & s) { static AliveCursor cursor; - cursor++; - cout << CLEARLN << cursor << " " << s; - cout << std::flush; + if (isatty(1)) + { + cursor++; + cout << CLEARLN << cursor << " " << s; + cout << std::flush; + } + else + { + cout << '.'; + } } // ---------------------------------------------------------------------------- @@ -107,6 +121,9 @@ void OutNormal::progressStart(const std::string & id, { if (progressFilter()) return; + + if (!isatty(1)) + cout << label << ' '; if (is_tick) display_tick(id, label); @@ -131,7 +148,10 @@ void OutNormal::progressEnd(const std::string & id, const string & label, bool e return; static AliveCursor cursor; - cout << CLEARLN << cursor.done() << " " << label << std::flush << endl; + if (isatty(1)) + cout << CLEARLN << cursor.done() << " " << label << std::flush << endl; + else + cout << cursor.done() << std::flush << endl; } // progress with download rate @@ -141,12 +161,18 @@ void OutNormal::dwnldProgressStart(const zypp::Url & uri) return; static AliveCursor cursor; - cout << CLEARLN << cursor << " " << _("Downloading:") << " "; + if (isatty(1)) + cout << CLEARLN << cursor << " " << _("Downloading:") << " "; + else + cout << _("Downloading:") << " "; if (verbosity() == DEBUG) cout << uri; //! \todo shorten to fit the width of the terminal else cout << zypp::Pathname(uri.getPathName()).basename(); - cout << " [" << _("starting") << "]"; //! \todo align to the right + if (isatty(1)) + cout << " [" << _("starting") << "]"; //! \todo align to the right + else + cout << " [" ; cout << std::flush; } @@ -156,6 +182,11 @@ void OutNormal::dwnldProgress(const zypp::Url & uri, { if (verbosity() < NORMAL) return; + if (!isatty(1)) + { + cout << '.' << std::flush; + return; + } static AliveCursor cursor; cout << CLEARLN << cursor++ << " " << _("Downloading:") << " "; @@ -183,12 +214,16 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error) return; static AliveCursor cursor; - cout << CLEARLN << cursor.done() << " " << _("Downloading:") << " "; - if (verbosity() == DEBUG) - cout << uri; //! \todo shorten to fit the width of the terminal - else - cout << zypp::Pathname(uri.getPathName()).basename(); - cout << " [" << (error ? _("error") : _("done")); + if (isatty(1)) + { + cout << CLEARLN << cursor.done() << " " << _("Downloading:") << " "; + if (verbosity() == DEBUG) + cout << uri; //! \todo shorten to fit the width of the terminal + else + cout << zypp::Pathname(uri.getPathName()).basename(); + cout << " ["; + } + cout << (error ? _("error") : _("done")); if (rate >= 0) cout << " (" << zypp::ByteCount(rate) << "/s)"; cout << "]"; -- 2.7.4