Browse files

Try moving progress bars

  • Loading branch information...
1 parent 0192428 commit ce25ce010eb4f010b343fcc9f336b64989c54655 @mlandres mlandres committed Apr 18, 2012
Showing with 72 additions and 45 deletions.
  1. +24 −1 src/output/Out.cc
  2. +1 −0 src/output/Out.h
  3. +47 −44 src/output/OutNormal.cc
View
25 src/output/Out.cc
@@ -1,6 +1,8 @@
#include <iostream>
#include <sstream>
+#include <zypp/AutoDispose.h>
+
#include "Out.h"
#include "Table.h"
@@ -19,7 +21,28 @@ std::string TermLine::get( unsigned width_r, SplitFlags flags_r, char exp_r ) co
if ( diff > 0 )
{
// expand...
- return l + std::string( diff, exp_r ) + r;
+ if ( ! flags_r.testFlag( SF_EXPAND ) )
+ return l + r;
+
+ if ( percentHint < 0 || percentHint > 100 )
+ return l + std::string( diff, exp_r ) + r;
+
+ // else: draw % indicator
+ // -------
+ // <1%>===
+ // .<99%>=
+ // .<100%>
+ if ( percentHint == 0 )
+ return zypp::str::Str() << l << std::string( diff, '-' ) << r;
+
+ int pc = diff * percentHint / 100;
+ if ( diff < 6 ) // not enough space for fancy stuff
+ return l + std::string( pc, '.' ) + std::string( diff-pc, '=' ) + r;
+
+ // else: less boring
+ std::string tag( zypp::str::Str() << '<' << percentHint << "%>" );
+ pc = ( pc > tag.size() ? pc - tag.size() : 0 );
+ return zypp::str::Str() << l << std::string( pc, '.' ) << tag << std::string( diff-pc-tag.size(), '=' ) << r;
}
else if ( diff < 0 )
{
View
1 src/output/Out.h
@@ -35,6 +35,7 @@ struct 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::DefaultIntegral<int,-1> percentHint; //< draw progress indicator in expanded space if in [0,100]
zypp::str::Str lhs; //< left side
zypp::str::Str rhs; //< right side
View
91 src/output/OutNormal.cc
@@ -13,6 +13,7 @@
#include <zypp/Pathname.h>
#include <zypp/ByteCount.h> // for download progress reporting
+#include <zypp/base/Logger.h>
#include <zypp/base/String.h> // for toUpper()
#include "main.h"
@@ -126,28 +127,24 @@ void OutNormal::displayProgress (const string & s, int percent)
if (_isatty)
{
- TermLine outstr( TermLine::SF_CRUSH, '.' );
- outstr.lhs << s;
- outstr.rhs << " [";
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' );
+ outstr.lhs << s << ' ';
+
// dont display percents if invalid
- if (percent >= 0 && percent <= 100)
- {
- outstr.rhs << percent << "%";
- }
- else
+ if ( percent >= 0 && percent <= 100 )
{
- ++cursor;
- outstr.rhs << cursor.current();
+ outstr.percentHint = percent;
}
- outstr.rhs << "]";
+ ++cursor;
+ outstr.rhs << '[' << cursor.current() << ']';
if(_oneup)
cout << CLEARLN << CURSORUP(1);
cout << CLEARLN;
std::string outline( outstr.get( termwidth() ) );
cout << outline << std::flush;
- _oneup = (outline.length() > termwidth());
+ _oneup = ( outline.length() > termwidth() );
}
else
cout << '.' << std::flush;
@@ -161,20 +158,21 @@ void OutNormal::displayTick (const string & s)
if (_isatty)
{
- string outline = s + " [";
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' );
++cursor;
- outline += cursor.current();
- outline += "]";
+ outstr.lhs << s << ' ';
+ outstr.rhs << '[' << cursor.current() << ']';
+
if(_oneup)
- cout << CLEARLN << CURSORUP(1) << CLEARLN << outline;
- else
- cout << CLEARLN << outline;
+ cout << CLEARLN << CURSORUP(1);
+ cout << CLEARLN;
- _oneup = (outline.length() > termwidth());
+ std::string outline( outstr.get( termwidth() ) );
+ cout << outline << std::flush;
+ _oneup = ( outline.length() > termwidth() );
}
else
- cout << '.';
- cout << std::flush;
+ cout << '.' << std::flush;
}
// ----------------------------------------------------------------------------
@@ -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, '.' );
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '.' );
if (_isatty)
{
if(_oneup)
@@ -228,8 +226,8 @@ void OutNormal::progressEnd(const std::string & id, const string & label, bool e
}
cout << CLEARLN;
- outstr.lhs << label;
- outstr.rhs << " [";
+ outstr.lhs << label << ' ';
+ outstr.rhs << '[';
if (error)
{
// a bit clmupsy and not perfect: hidden char counting
@@ -244,7 +242,7 @@ void OutNormal::progressEnd(const std::string & id, const string & label, bool e
else
outstr.rhs << (error ? _("error") : _("done"));
- outstr.rhs << "]";
+ outstr.rhs << ']';
std::string outline( outstr.get( termwidth() ) );
cout << outline << endl << std::flush;
@@ -263,16 +261,17 @@ void OutNormal::dwnldProgressStart(const zypp::Url & uri)
if (_isatty)
cout << CLEARLN;
- TermLine outstr( TermLine::SF_CRUSH, '.' );
- outstr.lhs << _("Retrieving:") << " ";
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' );
+ outstr.lhs << _("Retrieving:");
if (verbosity() == DEBUG)
- outstr.lhs << uri;
+ outstr.lhs << uri << ' ';
else
outstr.lhs << zypp::Pathname(uri.getPathName()).basename();
+ outstr.lhs << ' ';
if (_isatty)
- outstr.rhs << " [" << _("starting") << "]";
+ outstr.rhs << '[' << _("starting") << ']';
else
- outstr.rhs << " [" ;
+ outstr.rhs << '[' ;
std::string outline( outstr.get( termwidth() ) );
cout << outline << std::flush;
@@ -298,22 +297,25 @@ void OutNormal::dwnldProgress(const zypp::Url & uri,
cout << CLEARLN << CURSORUP(1);
cout << CLEARLN;
- TermLine outstr( TermLine::SF_CRUSH, '.' );
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '-' );
outstr.lhs << _("Retrieving:") << " ";
if (verbosity() == DEBUG)
outstr.lhs << uri;
else
outstr.lhs << zypp::Pathname(uri.getPathName()).basename();
+ outstr.lhs << ' ';
+
// dont display percents if invalid
- if ((value >= 0 && value <= 100) || rate >= 0)
- {
- outstr.rhs << " [";
- if (value >= 0 && value <= 100)
- outstr.rhs << value << "%";
- if (rate >= 0)
- outstr.rhs << " (" << zypp::ByteCount(rate) << "/s)";
- outstr.rhs << "]";
- }
+ if ( value >= 0 && value <= 100 )
+ outstr.percentHint = value;
+
+ static AliveCursor cursor;
+ ++cursor;
+ outstr.rhs << '[' << cursor.current();
+ if (rate > 0 )
+ outstr.rhs << " (" << zypp::ByteCount(rate) << "/s)";
+ outstr.rhs << ']';
+
std::string outline( outstr.get( termwidth() ) );
cout << outline << std::flush;
@@ -329,7 +331,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, '.' );
+ TermLine outstr( TermLine::SF_CRUSH | TermLine::SF_EXPAND, '.' );
if (_isatty)
{
if(_oneup)
@@ -340,7 +342,8 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error)
outstr.lhs << uri;
else
outstr.lhs << zypp::Pathname(uri.getPathName()).basename();
- outstr.rhs << " [";
+ outstr.lhs << ' ';
+ outstr.rhs << '[';
if (error)
{
// a bit clmupsy and not perfect: hidden char counting
@@ -355,9 +358,9 @@ void OutNormal::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error)
else
outstr.rhs << (error ? _("error") : _("done"));
- if (rate >= 0)
+ if (rate > 0)
outstr.rhs << " (" << zypp::ByteCount(rate) << "/s)";
- outstr.rhs << "]";
+ outstr.rhs << ']';
std::string outline( outstr.get( termwidth() ) );
cout << outline << endl << std::flush;

0 comments on commit ce25ce0

Please sign in to comment.