From 05edb7040998ca545d23bf2d402a50b93bc32aad Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Thu, 13 Sep 2012 13:38:02 +0200 Subject: [PATCH] Fix zypper output if stdout is not a tty (bnc#779716) --- src/output/Out.cc | 4 +++- src/output/Out.h | 2 +- src/output/OutNormal.cc | 14 ++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/output/Out.cc b/src/output/Out.cc index 36c9a66..0f6f2d6 100644 --- a/src/output/Out.cc +++ b/src/output/Out.cc @@ -1,3 +1,5 @@ +#include + #include #include @@ -28,7 +30,7 @@ std::string TermLine::get( unsigned width_r, SplitFlags flags_r, char exp_r ) co if ( diff > 0 ) { // expand... - if ( ! flags_r.testFlag( SF_EXPAND ) ) + if ( ! ( flags_r.testFlag( SF_EXPAND ) && ::isatty(STDOUT_FILENO) ) ) return zypp::str::Str() << l << r; if ( percentHint < 0 || percentHint > 100 ) diff --git a/src/output/Out.h b/src/output/Out.h index 21eb770..052cf9f 100644 --- a/src/output/Out.h +++ b/src/output/Out.h @@ -24,7 +24,7 @@ struct TermLine { SF_CRUSH = 1<<0, //< truncate lhs, then rhs SF_SPLIT = 1<<1, //< split line across two - SF_EXPAND = 1<<2 //< expand short lines + SF_EXPAND = 1<<2 //< expand short lines iff stdout is a tty }; ZYPP_DECLARE_FLAGS( SplitFlags, SplitFlag ); diff --git a/src/output/OutNormal.cc b/src/output/OutNormal.cc index 72f3153..066c28c 100644 --- a/src/output/OutNormal.cc +++ b/src/output/OutNormal.cc @@ -24,8 +24,6 @@ using namespace std; -#define SF_EXPAND_IF_TTY ( _isatty ? TermLine::SF_EXPAND : TermLine::SplitFlags() ) - OutNormal::OutNormal(Verbosity verbosity) : Out(TYPE_NORMAL, verbosity), _use_colors(false), _isatty(isatty(STDOUT_FILENO)), _newline(true), _oneup(false) @@ -129,7 +127,7 @@ void OutNormal::displayProgress (const string & s, int percent) if (_isatty) { - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '-' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' ); outstr.lhs << s << ' '; // dont display percents if invalid @@ -160,7 +158,7 @@ void OutNormal::displayTick (const string & s) if (_isatty) { - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '-' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' ); ++cursor; outstr.lhs << s << ' '; outstr.rhs << '[' << cursor.current() << ']'; @@ -218,7 +216,7 @@ void OutNormal::progressEnd(const std::string & id, const string & label, bool e if (!error && _use_colors) cout << get_color(COLOR_CONTEXT_MSG_STATUS); - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '.' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '.' ); if (_isatty) { if(_oneup) @@ -263,7 +261,7 @@ void OutNormal::dwnldProgressStart(const zypp::Url & uri) if (_isatty) cout << CLEARLN; - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '-' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' ); outstr.lhs << _("Retrieving:") << ' '; if (verbosity() == DEBUG) outstr.lhs << uri; @@ -299,7 +297,7 @@ void OutNormal::dwnldProgress(const zypp::Url & uri, cout << CLEARLN << CURSORUP(1); cout << CLEARLN; - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '-' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' ); outstr.lhs << _("Retrieving:") << " "; if (verbosity() == DEBUG) outstr.lhs << uri; @@ -332,7 +330,7 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error) if (!error && _use_colors) cout << get_color(COLOR_CONTEXT_MSG_STATUS); - TermLine outstr( TermLine::SF_CRUSH | SF_EXPAND_IF_TTY, '.' ); + TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '.' ); if (_isatty) { if(_oneup) -- 2.7.4