Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <zypper> master : Do not colorize summary output when viewing in pager
  • From: Ján Kupec <jkupec@xxxxxxx>
  • Date: Sun, 7 Jun 2009 12:34:25 +0200
  • Message-id: <E1MDcA5-0007Au-HU@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit f929ec7a5ef489da8c1654a05300fef43a829775
Author: Ján Kupec <jkupec@xxxxxxx>
Date: Sun Jun 7 12:34:25 2009 +0200

Do not colorize summary output when viewing in pager
---
src/Summary.cc | 13 ++++++++++++-
src/Summary.h | 3 +++
src/Zypper.h | 2 +-
src/solve-commit.cc | 2 ++
4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/Summary.cc b/src/Summary.cc
index 00f46bb..820dda5 100644
--- a/src/Summary.cc
+++ b/src/Summary.cc
@@ -20,6 +20,7 @@
#include "utils/colors.h"
#include "utils/misc.h"
#include "Table.h"
+#include "Zypper.h"

#include "Summary.h"

@@ -38,7 +39,7 @@ bool Summary::ResPairNameCompare::operator()(
// --------------------------------------------------------------------------

Summary::Summary(const zypp::ResPool & pool, const ViewOptions options)
- : _viewop(options), _wrap_width(80)
+ : _viewop(options), _wrap_width(80), _force_no_color(false)
{
readPool(pool);
}
@@ -724,6 +725,16 @@ void Summary::writePackageCounts(ostream & out)

void Summary::dumpTo(ostream & out)
{
+ struct SetColor
+ {
+ SetColor(bool force) : docolors(Zypper::instance()->config().do_colors)
+ { if (force) Zypper::instance()->config().do_colors = false; }
+ ~SetColor()
+ { Zypper::instance()->config().do_colors = docolors; }
+ bool docolors;
+ };
+ SetColor setcolor(_force_no_color);
+
_wrap_width = get_screen_width();

writeNewlyInstalled(out);
diff --git a/src/Summary.h b/src/Summary.h
index 44afcec..7cada03 100644
--- a/src/Summary.h
+++ b/src/Summary.h
@@ -62,6 +62,8 @@ public:
{ _viewop = (ViewOptions) (_viewop & ~option); }
void toggleViewOption(const ViewOptions option)
{ _viewop & option ? unsetViewOption(option) : setViewOption(option); }
+ void setForceNoColor(bool value = true)
+ { _force_no_color = value; }

void writeNewlyInstalled(std::ostream & out);
void writeRemoved(std::ostream & out);
@@ -102,6 +104,7 @@ private:
private:
ViewOptions _viewop;
mutable unsigned _wrap_width;
+ bool _force_no_color;

bool _need_reboot;
bool _need_restart;
diff --git a/src/Zypper.h b/src/Zypper.h
index 0eead52..ad37aef 100644
--- a/src/Zypper.h
+++ b/src/Zypper.h
@@ -162,7 +162,7 @@ public:

// setters & getters
Out & out();
- const Config & config() const { return _config; }
+ Config & config() { return _config; }
const GlobalOptions & globalOpts() const { return _gopts; }
const parsed_opts & cOpts() const { return _copts; }
const ZypperCommand & command() const { return _command; }
diff --git a/src/solve-commit.cc b/src/solve-commit.cc
index 5237ca8..4969129 100755
--- a/src/solve-commit.cc
+++ b/src/solve-commit.cc
@@ -552,7 +552,9 @@ void solve_and_commit (Zypper & zypper)
case 8: // g - view in pager
{
ostringstream s;
+ summary.setForceNoColor(true);
summary.dumpTo(s);
+ summary.setForceNoColor(false);
show_text_in_pager(s.str());
break;
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages