From 234956bbdbbb78a97fb9ccd566553bf902a79d1d Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 10 Jul 2007 16:30:57 +0000 Subject: [PATCH] Finalize progress lines with a * so you dont get a random / or \ or | --- src/AliveCursor.h | 6 ++++++ src/zypper-callbacks.cc | 19 ++++++++++++++++++- src/zypper-callbacks.h | 2 ++ src/zypper-source-callbacks.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/AliveCursor.h b/src/AliveCursor.h index e2b25ac..72cf0b1 100644 --- a/src/AliveCursor.h +++ b/src/AliveCursor.h @@ -49,6 +49,12 @@ class AliveCursor return *this; } + AliveCursor & done() + { + _current = '*'; + return *this; + } + private: char _current; }; diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index 27ec3b4..15c928e 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -10,13 +10,30 @@ using namespace std; void display_progress (const string& s, int percent) { static AliveCursor cursor; - cout_v << CLEARLN << cursor++ << " " << s; + if ( percent == 100 ) + cout_v << CLEARLN << cursor.done() << " " << s; + else + cout_v << CLEARLN << cursor++ << " " << s; // dont display percents if invalid if (percent >= 0 && percent <= 100) cout_v << " [" << percent << "%]"; cout_v << flush; } +void display_tick (const string& s) { + static AliveCursor cursor; + + cout_v << CLEARLN << cursor++ << " " << s; + cout_v << flush; +} + +void display_done (const string& s) { + static AliveCursor cursor; + + cout_v << CLEARLN << cursor.done() << " " << s; + cout_v << flush; +} + void display_done () { cout_v << endl; } diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 7f92a87..259b368 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -22,6 +22,8 @@ enum Error { }; */ void display_progress (const std::string& s, int percent); +void display_tick (const std::string& s); +void display_done (const std::string& s); // newline if normal progress is on single line void display_done (); diff --git a/src/zypper-source-callbacks.h b/src/zypper-source-callbacks.h index 0d0e114..31f61c0 100644 --- a/src/zypper-source-callbacks.h +++ b/src/zypper-source-callbacks.h @@ -211,6 +211,45 @@ struct DownloadResolvableReportReceiver : public zypp::callback::ReceiveReport +{ + void tick( const zypp::ProgressData &data ) + { + if ( data.reportAlive() ) + { + display_tick ( data.name() ); + } + else + { + display_progress ( data.name() , data.val() ); + } + + + } + + virtual void start( const zypp::ProgressData &data ) + { tick(data); } + + virtual bool progress( const zypp::ProgressData &data ) + { + tick(data); + return true; + } + +// virtual Action problem( zypp::Repository /*repo*/, Error error, const std::string & description ) +// { +// display_done (); +// display_error (error, description); +// return (Action) read_action_ari (); +// } + + virtual void finish( const zypp::ProgressData &data ) + { + display_done( data.name() ); + } +}; + + struct RepoReportReceiver : public zypp::callback::ReceiveReport { virtual void start( zypp::Repository repo, const std::string & task ) @@ -263,12 +302,14 @@ class SourceCallbacks { // ZmartRecipients::ProbeSourceReceive _sourceProbeReport; ZmartRecipients::RepoReportReceiver _repoReport; ZmartRecipients::DownloadResolvableReportReceiver _downloadReport; + ZmartRecipients::ProgressReportReceiver _progressReport; public: SourceCallbacks() { // _sourceProbeReport.connect(); _repoReport.connect(); _downloadReport.connect(); + _progressReport.connect(); } ~SourceCallbacks() @@ -276,6 +317,7 @@ class SourceCallbacks { // _sourceProbeReport.disconnect(); _repoReport.disconnect(); _downloadReport.disconnect(); + _progressReport.disconnect(); } }; -- 2.7.4