aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-07-20 18:55:26 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-07-20 18:55:26 +0100
commit00a91428b6807b3e3b3428f2f7daaf74c607dfb4 (patch)
tree8da7857ae5236f2d6992c512389e138e3d18deb4
parentbccdc4003d3fcaf4562ec85d4d6f0288ca34150d (diff)
downloadpaludis-00a91428b6807b3e3b3428f2f7daaf74c607dfb4.tar.gz
paludis-00a91428b6807b3e3b3428f2f7daaf74c607dfb4.tar.xz
Better progress indicator
-rw-r--r--src/output/console_install_task.cc74
-rw-r--r--src/output/console_install_task.hh3
2 files changed, 52 insertions, 25 deletions
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index 442ac78..f8ecd2e 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -196,45 +196,69 @@ ConsoleInstallTask::try_to_set_targets_from_user_specs(const std::tr1::shared_pt
return is_ok;
}
-void
-ConsoleInstallTask::on_build_deplist_pre()
+struct ConsoleInstallTask::CallbackDisplayer
{
- output_activity_start_message("Building dependency list: ");
- output_xterm_title("Building dependency list");
+ Mutex mutex;
- _notifier_callback.reset(new NotifierCallbackID(environment()->add_notifier_callback(
- std::tr1::bind(std::tr1::mem_fn(&ConsoleInstallTask::_notifier_callback_fn),
- this, std::tr1::placeholders::_1))));
-}
+ std::ostream & stream;
+ int width, step, metadata;
-namespace
-{
- struct CallbackDisplayer
+ CallbackDisplayer(std::ostream & s) :
+ stream(s),
+ width(0),
+ step(0),
+ metadata(0)
{
- std::ostream & stream;
+ }
- CallbackDisplayer(std::ostream & s) :
- stream(s)
+ void update()
+ {
+ std::string s;
+ if (step > 0)
+ s.append("steps: " + stringify(step));
+ if (metadata > 0)
{
+ if (! s.empty())
+ s.append(", ");
+ s.append("metadata: " + stringify(metadata));
}
- void visit(const NotifierCallbackResolverStepEvent &)
- {
- stream << "." << std::flush;
- }
+ stream << std::string(width, '\010');
+ stream << " " << s << std::flush;
+ width = s.length() + 1;
+ }
- void visit(const NotifierCallbackGeneratingMetadataEvent &)
- {
- stream << "*" << std::flush;
- }
- };
+ void visit(const NotifierCallbackResolverStepEvent &)
+ {
+ Lock lock(mutex);
+ ++step;
+ update();
+ }
+
+ void visit(const NotifierCallbackGeneratingMetadataEvent &)
+ {
+ Lock lock(mutex);
+ ++metadata;
+ update();
+ }
+};
+
+void
+ConsoleInstallTask::on_build_deplist_pre()
+{
+ output_activity_start_message("Building dependency list: ");
+ output_xterm_title("Building dependency list");
+
+ _callback_displayer.reset(new CallbackDisplayer(output_stream()));
+ _notifier_callback.reset(new NotifierCallbackID(environment()->add_notifier_callback(
+ std::tr1::bind(std::tr1::mem_fn(&ConsoleInstallTask::_notifier_callback_fn),
+ this, std::tr1::placeholders::_1))));
}
void
ConsoleInstallTask::_notifier_callback_fn(const NotifierCallbackEvent & e)
{
- CallbackDisplayer d(output_stream());
- e.accept(d);
+ e.accept(*_callback_displayer);
}
void
diff --git a/src/output/console_install_task.hh b/src/output/console_install_task.hh
index 90ee086..6228002 100644
--- a/src/output/console_install_task.hh
+++ b/src/output/console_install_task.hh
@@ -101,6 +101,8 @@ namespace paludis
typedef std::map<std::string, ChoiceValueDescriptions> ChoiceDescriptions;
private:
+ struct CallbackDisplayer;
+
int _counts[last_count];
unsigned long _download_size;
bool _download_size_overflow;
@@ -110,6 +112,7 @@ namespace paludis
bool _resolution_finished;
+ std::tr1::shared_ptr<CallbackDisplayer> _callback_displayer;
std::tr1::shared_ptr<NotifierCallbackID> _notifier_callback;
void _notifier_callback_fn(const NotifierCallbackEvent &);