#include "output/prompt.h"
-static bool report_again(timespec * last)
+static bool report_again( timespec & lastTime_r, int & lastValue_r, int currentValue_r )
{
- // don't report more often than 5 times per sec
+ // Don't report more often than 5 times per sec,
+ // but also leaving 0%, more than 20% step and reaching 100%
timespec now;
- clock_gettime(CLOCK_REALTIME, &now);
- if (now.tv_sec > last->tv_sec ||
- (now.tv_sec == last->tv_sec && now.tv_nsec > last->tv_nsec + 200000000L))
+ clock_gettime( CLOCK_REALTIME, &now );
+ if ( now.tv_sec > lastTime_r.tv_sec
+ || ( now.tv_sec == lastTime_r.tv_sec && now.tv_nsec > lastTime_r.tv_nsec + 200000000L )
+ || ( lastValue_r != currentValue_r && ( lastValue_r + 20 <= currentValue_r || lastValue_r == 0 || currentValue_r == 100 ) ) )
{
- *last = now;
+ lastTime_r = now;
+ lastValue_r = currentValue_r;
return true;
}
- else
- return false;
+ return false;
}
///////////////////////////////////////////////////////////////////
{
std::string _label;
timespec _last_reported;
+ zypp::DefaultIntegral<int,0> _last_percent;
virtual void start( zypp::Resolvable::constPtr resolvable )
{
::clock_gettime(CLOCK_REALTIME, &_last_reported);
+ _last_percent.reset();
// translators: This text is a progress display label e.g. "Removing packagename-x.x.x [42%]"
_label = boost::str(boost::format(_("Removing %s-%s"))
% resolvable->name() % resolvable->edition());
Zypper::instance()->out().progressStart("remove-resolvable", _label);
}
- virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
+ virtual bool progress( int value, zypp::Resolvable::constPtr resolvable )
{
// don't report too often
- if (!report_again(&_last_reported))
- return true;
-
- Zypper::instance()->out().progress("remove-resolvable", _label, value);
+ if ( report_again( _last_reported, _last_percent, value ) )
+ {
+ Zypper::instance()->out().progress( "remove-resolvable", _label, value );
+ }
return true;
}
zypp::Resolvable::constPtr _resolvable;
std::string _label;
timespec _last_reported;
-
- void display_step( zypp::Resolvable::constPtr resolvable, int value )
- {
- }
+ zypp::DefaultIntegral<int,0> _last_percent;
virtual void start( zypp::Resolvable::constPtr resolvable )
{
clock_gettime(CLOCK_REALTIME, &_last_reported);
+ _last_percent.reset();
_resolvable = resolvable;
// TranslatorExplanation This text is a progress display label e.g. "Installing foo-1.1.2 [42%]"
_label = boost::str(boost::format(_("Installing: %s-%s"))
Zypper::instance()->out().progressStart("install-resolvable", _label);
}
- virtual bool progress(int value, zypp::Resolvable::constPtr resolvable)
+ virtual bool progress( int value, zypp::Resolvable::constPtr resolvable )
{
// don't report too often
- if (!report_again(&_last_reported))
- return true;
-
- Zypper::instance()->out().progress("install-resolvable", _label, value);
+ if ( report_again( _last_reported, _last_percent, value ) )
+ {
+ Zypper::instance()->out().progress( "install-resolvable", _label, value );
+ }
return true;
}
if ( width_r == 0 )
return l + r; // plain sring if zero width
- if ( ! flags_r && flagsHint )
- flags_r = flagsHint;
-
unsigned llen( l.length() - lhidden );
unsigned rlen( r.length() - rhidden );
int diff = width_r - llen - rlen;
};
ZYPP_DECLARE_FLAGS( SplitFlags, SplitFlag );
- TermLine() {}
+ TermLine( SplitFlags flags_r, char exp_r ) : flagsHint( flags_r ), expHint( exp_r ) {}
TermLine( SplitFlags flags_r ) : flagsHint( flags_r ) {}
+ TermLine( char exp_r ) : expHint( exp_r ) {}
+ TermLine() {}
+
+ SplitFlags flagsHint; //< flags to use if not passed to \ref get
+ zypp::DefaultIntegral<char,' '> expHint; //< expand char to use if not passed to \ref get
zypp::str::Str lhs; //< left side
zypp::str::Str rhs; //< right side
zypp::DefaultIntegral<unsigned,0> lhidden; //< size of embedded esc sequences
zypp::DefaultIntegral<unsigned,0> rhidden; //< size of embedded esc sequences
- SplitFlags flagsHint; //< flags to use if no flags passed to \ref get
+
/** Return plain line made of lhs + rhs */
std::string get() const
/** Return line optionally formated according to \a width_r and \a flags_r.
* If \a width_r or \a flags_r is zero a plain line made of lhs + rhs is returned.
*/
- std::string get( unsigned width_r, SplitFlags flags_r = SplitFlag(), char exp_r = ' ' ) const;
+ std::string get( unsigned width_r, SplitFlags flags_r, char exp_r ) const;
+ /** \overload */
+ std::string get( unsigned width_r, SplitFlags flags_r ) const
+ { return get( width_r, flags_r, expHint ); }
+ /** \overload */
+ std::string get( unsigned width_r, char exp_r ) const
+ { return get( width_r, flagsHint, exp_r ); }
+ /** \overload */
+ std::string get( unsigned width_r ) const
+ { return get( width_r, flagsHint, expHint ); }
};
ZYPP_DECLARE_OPERATORS_FOR_FLAGS( TermLine::SplitFlags );
if (_isatty)
{
- string outline = s + " [";
+ TermLine outstr( TermLine::SF_CRUSH, '.' );
+ outstr.lhs << s;
+ outstr.rhs << " [";
// dont display percents if invalid
if (percent >= 0 && percent <= 100)
{
- std::ostringstream oss;
- oss << percent << "%";
- outline += oss.str();
+ outstr.rhs << percent << "%";
}
else
{
++cursor;
- outline += cursor.current();
+ outstr.rhs << cursor.current();
}
- outline += "]";
+ outstr.rhs << "]";
if(_oneup)
- cout << CLEARLN << CURSORUP(1) << CLEARLN << outline;
- else
- cout << CLEARLN << outline;
+ cout << CLEARLN << CURSORUP(1);
+ cout << CLEARLN;
+ std::string outline( outstr.get( termwidth() ) );
+ cout << outline << std::flush;
_oneup = (outline.length() > termwidth());
}
else
- cout << '.';
- cout << std::flush;
+ cout << '.' << std::flush;
}
// ----------------------------------------------------------------------------
if (!error && _use_colors)
cout << get_color(COLOR_CONTEXT_MSG_STATUS);
+ TermLine outstr( TermLine::SF_CRUSH, '.' );
if (_isatty)
{
if(_oneup)
{
- cout << CLEARLN << CURSORUP(1) << CLEARLN;
+ cout << CLEARLN << CURSORUP(1);
_oneup = false;
}
+ cout << CLEARLN;
+
+ outstr.lhs << label;
+ outstr.rhs << " [";
+ if (error)
+ {
+ // a bit clmupsy and not perfect: hidden char counting
+ unsigned tag( std::string(outstr.rhs).size() );
+ std::string errstr( _("error") );
+ fprint_color(outstr.rhs._str, errstr, COLOR_CONTEXT_NEGATIVE);
+ outstr.rhidden += unsigned(std::string(outstr.rhs).size() - errstr.size()) - tag ;
+ }
else
- cout << CLEARLN;
- cout << label << " [";
+ outstr.rhs << _("done");
}
-
- if (error)
- print_color(_("error"), COLOR_CONTEXT_NEGATIVE);
else
- cout << _("done");
+ outstr.rhs << (error ? _("error") : _("done"));
- cout << "]";
+ outstr.rhs << "]";
+
+ std::string outline( outstr.get( termwidth() ) );
+ cout << outline << endl << std::flush;
+ _newline = true;
if (!error && _use_colors)
cout << COLOR_RESET;
-
- cout << endl << std::flush;
- _newline = true;
}
// progress with download rate
if (_isatty)
cout << CLEARLN;
- TermLine outstr( TermLine::SF_CRUSH );
+ TermLine outstr( TermLine::SF_CRUSH, '.' );
outstr.lhs << _("Retrieving:") << " ";
if (verbosity() == DEBUG)
outstr.lhs << uri;
cout << CLEARLN << CURSORUP(1);
cout << CLEARLN;
- TermLine outstr( TermLine::SF_CRUSH );
+ TermLine outstr( TermLine::SF_CRUSH, '.' );
outstr.lhs << _("Retrieving:") << " ";
if (verbosity() == DEBUG)
outstr.lhs << uri;
if (!error && _use_colors)
cout << get_color(COLOR_CONTEXT_MSG_STATUS);
- TermLine outstr( TermLine::SF_CRUSH );
+ TermLine outstr( TermLine::SF_CRUSH, '.' );
if (_isatty)
{
if(_oneup)