aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-12-06 20:04:32 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-12-06 23:25:04 +0000
commit8c2cb0ca3227f39671631c982ae664d9af006c56 (patch)
treee4ca9c9a7913a12b99e0f4e00611f15c8cbc41d3
parent1d7d3717751952e8468b5b95927094924a83da58 (diff)
downloadpaludis-8c2cb0ca3227f39671631c982ae664d9af006c56.tar.gz
paludis-8c2cb0ca3227f39671631c982ae664d9af006c56.tar.xz
Don't show notification unless isatty
-rw-r--r--src/clients/cave/cmd_resolve_display_callback.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/clients/cave/cmd_resolve_display_callback.cc b/src/clients/cave/cmd_resolve_display_callback.cc
index 696a7be..a49f8ee 100644
--- a/src/clients/cave/cmd_resolve_display_callback.cc
+++ b/src/clients/cave/cmd_resolve_display_callback.cc
@@ -23,6 +23,7 @@
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <iostream>
#include <map>
+#include <unistd.h>
using namespace paludis;
using namespace cave;
@@ -37,9 +38,12 @@ namespace paludis
mutable std::string stage;
mutable unsigned width;
+ bool output;
+
Implementation() :
stage("Resolving: "),
- width(stage.length())
+ width(stage.length()),
+ output(::isatty(1))
{
}
};
@@ -49,23 +53,31 @@ namespace paludis
DisplayCallback::DisplayCallback() :
PrivateImplementationPattern<DisplayCallback>(new Implementation<DisplayCallback>)
{
- std::cout << _imp->stage << std::flush;
+ if (_imp->output)
+ std::cout << _imp->stage << std::flush;
}
DisplayCallback::~DisplayCallback()
{
- std::cout << std::endl << std::endl;
+ if (_imp->output)
+ std::cout << std::endl << std::endl;
}
void
DisplayCallback::operator() (const NotifierCallbackEvent & event) const
{
+ if (! _imp->output)
+ return;
+
event.accept(*this);
}
void
DisplayCallback::operator() (const ResolverRestart &) const
{
+ if (! _imp->output)
+ return;
+
Lock lock(_imp->mutex);
++_imp->steps.insert(std::make_pair("restarts", 0)).first->second;
update();
@@ -74,6 +86,9 @@ DisplayCallback::operator() (const ResolverRestart &) const
void
DisplayCallback::visit(const NotifierCallbackGeneratingMetadataEvent & e) const
{
+ if (! _imp->output)
+ return;
+
Lock lock(_imp->mutex);
++_imp->metadata.insert(std::make_pair(stringify(e.repository()), 0)).first->second;
update();
@@ -82,6 +97,9 @@ DisplayCallback::visit(const NotifierCallbackGeneratingMetadataEvent & e) const
void
DisplayCallback::visit(const NotifierCallbackResolverStageEvent & e) const
{
+ if (! _imp->output)
+ return;
+
Lock lock(_imp->mutex);
_imp->stage = e.stage() + ": ";
update();
@@ -90,6 +108,9 @@ DisplayCallback::visit(const NotifierCallbackResolverStageEvent & e) const
void
DisplayCallback::visit(const NotifierCallbackResolverStepEvent &) const
{
+ if (! _imp->output)
+ return;
+
Lock lock(_imp->mutex);
++_imp->steps.insert(std::make_pair("steps", 0)).first->second;
update();
@@ -98,6 +119,9 @@ DisplayCallback::visit(const NotifierCallbackResolverStepEvent &) const
void
DisplayCallback::update() const
{
+ if (! _imp->output)
+ return;
+
std::string s(_imp->stage);
bool first(true);