Do not colorize summary output when viewing in pager
authorJán Kupec <jkupec@suse.cz>
Sun, 7 Jun 2009 10:34:25 +0000 (12:34 +0200)
committerJán Kupec <jkupec@suse.cz>
Sun, 7 Jun 2009 10:34:25 +0000 (12:34 +0200)
src/Summary.cc
src/Summary.h
src/Zypper.h
src/solve-commit.cc

index 00f46bb..820dda5 100644 (file)
@@ -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);
index 44afcec..7cada03 100644 (file)
@@ -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;
index 0eead52..ad37aef 100644 (file)
@@ -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; }
index 5237ca8..4969129 100755 (executable)
@@ -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;
         }