Implement output stream adapter to support suppression of ansi color codes #2

Open
opened 2026-06-24 06:33:41 +02:00 by Ryan · 1 comment
Owner

Something like:

class formatted_output
{
  ostream& _os;
  bool _ansi_enabled{};
  
public:
  template<typename U>
  formatted_output&
  operator<<(U const& other)
  {
    _os << other;
    return *this;
  }
  
  formatted_output&
  operator<<(ansi const& a)
  {
    if (_ansi_enabled) {
      _os << a;
    }
    return *this;
  }
  
};

Use this adapter class for all things output, pass it around instead of raw ostream references.

Something like: ```cxx class formatted_output { ostream& _os; bool _ansi_enabled{}; public: template<typename U> formatted_output& operator<<(U const& other) { _os << other; return *this; } formatted_output& operator<<(ansi const& a) { if (_ansi_enabled) { _os << a; } return *this; } }; ``` Use this adapter class for all things output, pass it around instead of raw `ostream` references.
Ryan added the Kind/Enhancement
Priority
Medium
4
Kind/Feature
labels 2026-06-24 06:33:41 +02:00
Author
Owner

Also add --no-color option to options.hxx (to control _ansi_enabled).

Also add `--no-color` option to `options.hxx` (to control `_ansi_enabled`).
Sign in to join this conversation.