aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-27 23:04:23 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-08-27 23:04:23 +0100
commitd98d4a1a1679710ab074d77f4ef9ca5ace12fc4d (patch)
treeda3b783ecbdee866b667403900b2645b6e285d20
parent61abcbce1f0ed5a91eb3046f29847a33a090c846 (diff)
downloadpaludis-d98d4a1a1679710ab074d77f4ef9ca5ace12fc4d.tar.gz
paludis-d98d4a1a1679710ab074d77f4ef9ca5ace12fc4d.tar.xz
Nick cave's notifiers
-rw-r--r--src/clients/inquisitio/do_search.cc71
-rw-r--r--src/output/console_install_task.cc94
2 files changed, 131 insertions, 34 deletions
diff --git a/src/clients/inquisitio/do_search.cc b/src/clients/inquisitio/do_search.cc
index 02b5d35..31d4fee 100644
--- a/src/clients/inquisitio/do_search.cc
+++ b/src/clients/inquisitio/do_search.cc
@@ -57,12 +57,11 @@ namespace
struct DisplayCallback
{
mutable Mutex mutex;
- mutable int width, metadata, searched;
+ mutable unsigned width;
+ mutable std::map<std::string, int> metadata, steps;
DisplayCallback() :
- width(0),
- metadata(0),
- searched(0)
+ width(0)
{
}
@@ -71,39 +70,87 @@ namespace
event.accept(*this);
}
- void visit(const NotifierCallbackGeneratingMetadataEvent &) const
+ void visit(const NotifierCallbackGeneratingMetadataEvent & e) const
{
Lock lock(mutex);
- ++metadata;
+ ++metadata.insert(std::make_pair(stringify(e.repository()), 0)).first->second;
update();
}
void visit(const NotifierCallbackResolverStepEvent &) const
{
+ Lock lock(mutex);
+ ++steps.insert(std::make_pair("steps", 0)).first->second;
+ update();
}
void visit(const Searched &) const
{
Lock lock(mutex);
- ++searched;
+ ++steps.insert(std::make_pair("searched", 0)).first->second;
update();
}
void update() const
{
std::string s;
- if (0 != searched)
- s.append("searched: " + stringify(searched));
+ if (! steps.empty())
+ {
+ for (std::map<std::string, int>::const_iterator i(steps.begin()), i_end(steps.end()) ;
+ i != i_end ; ++i)
+ {
+ if (! s.empty())
+ s.append(", ");
+
+ s.append(stringify(i->second) + " " + i->first);
+ }
+ }
- if (0 != metadata)
+ if (! metadata.empty())
{
+ std::multimap<int, std::string> biggest;
+ for (std::map<std::string, int>::const_iterator i(metadata.begin()), i_end(metadata.end()) ;
+ i != i_end ; ++i)
+ biggest.insert(std::make_pair(i->second, i->first));
+
+ int t(0), n(0);
+ std::string ss;
+ for (std::multimap<int, std::string>::const_reverse_iterator i(biggest.rbegin()), i_end(biggest.rend()) ;
+ i != i_end ; ++i)
+ {
+ ++n;
+
+ if (n == 4)
+ {
+ ss.append(", ...");
+ break;
+ }
+
+ if (n < 4)
+ {
+ if (! ss.empty())
+ ss.append(", ");
+
+ ss.append(stringify(i->first) + " " + i->second);
+ }
+
+ t += i->first;
+ }
+
if (! s.empty())
s.append(", ");
- s.append("metadata: " + stringify(metadata) + " ");
+ s.append(stringify(t) + " metadata (" + ss + ")");
}
- std::cout << std::string(width, '\010') << s << std::flush;
+ std::cout << std::string(width, '\010') << s;
+
+ if (width > s.length())
+ std::cout
+ << std::string(width - s.length(), ' ')
+ << std::string(width - s.length(), '\010');
+
width = s.length();
+ std::cout << std::flush;
}
};
diff --git a/src/output/console_install_task.cc b/src/output/console_install_task.cc
index 0579e15..8f6fb71 100644
--- a/src/output/console_install_task.cc
+++ b/src/output/console_install_task.cc
@@ -73,6 +73,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
+#include <map>
using namespace paludis;
using std::cout;
@@ -201,46 +202,95 @@ struct ConsoleInstallTask::CallbackDisplayer
Mutex mutex;
std::ostream & stream;
- int width, step, metadata;
+ unsigned width;
+ std::map<std::string, int> metadata, steps;
CallbackDisplayer(std::ostream & s) :
stream(s),
- width(0),
- step(0),
- metadata(0)
+ width(0)
{
}
- void update()
+ void operator() (const NotifierCallbackEvent & event)
{
- std::string s;
- if (step > 0)
- s.append("steps: " + stringify(step));
- if (metadata > 0)
- {
- if (! s.empty())
- s.append(", ");
- s.append("metadata: " + stringify(metadata) + " ");
- }
-
- stream << std::string(width, '\010');
- stream << " " << s << std::flush;
- width = s.length() + 1;
+ event.accept(*this);
}
- void visit(const NotifierCallbackResolverStepEvent &)
+ void visit(const NotifierCallbackGeneratingMetadataEvent & e)
{
Lock lock(mutex);
- ++step;
+ ++metadata.insert(std::make_pair(stringify(e.repository()), 0)).first->second;
update();
}
- void visit(const NotifierCallbackGeneratingMetadataEvent &)
+ void visit(const NotifierCallbackResolverStepEvent &)
{
Lock lock(mutex);
- ++metadata;
+ ++steps.insert(std::make_pair("steps", 0)).first->second;
update();
}
+
+ void update()
+ {
+ std::string s;
+ if (! steps.empty())
+ {
+ for (std::map<std::string, int>::const_iterator i(steps.begin()), i_end(steps.end()) ;
+ i != i_end ; ++i)
+ {
+ if (! s.empty())
+ s.append(", ");
+
+ s.append(stringify(i->second) + " " + i->first);
+ }
+ }
+
+ if (! metadata.empty())
+ {
+ std::multimap<int, std::string> biggest;
+ for (std::map<std::string, int>::const_iterator i(metadata.begin()), i_end(metadata.end()) ;
+ i != i_end ; ++i)
+ biggest.insert(std::make_pair(i->second, i->first));
+
+ int t(0), n(0);
+ std::string ss;
+ for (std::multimap<int, std::string>::const_reverse_iterator i(biggest.rbegin()), i_end(biggest.rend()) ;
+ i != i_end ; ++i)
+ {
+ ++n;
+
+ if (n == 4)
+ {
+ ss.append(", ...");
+ break;
+ }
+
+ if (n < 4)
+ {
+ if (! ss.empty())
+ ss.append(", ");
+
+ ss.append(stringify(i->first) + " " + i->second);
+ }
+
+ t += i->first;
+ }
+
+ if (! s.empty())
+ s.append(", ");
+ s.append(stringify(t) + " metadata (" + ss + ")");
+ }
+
+ stream << std::string(width, '\010') << " " << s;
+
+ if (width > s.length())
+ stream
+ << std::string(width - s.length(), ' ')
+ << std::string(width - s.length(), '\010');
+
+ width = s.length() + 1;
+ stream << std::flush;
+ }
};
void