CGAL 6.2 - IO Streams
Loading...
Searching...
No Matches
CGAL::IO::Basic_color_streambuf< CharT, Traits > Class Template Reference

#include <CGAL/IO/Color_ostream.h>

Inherits from

std::basic_streambuf< CharT, std::char_traits< CharT > >, and std::char_traits< CharT >.

Definition

template<typename CharT, typename Traits = std::char_traits<CharT>>
class CGAL::IO::Basic_color_streambuf< CharT, Traits >

The class template Basic_color_streambuf wraps another basic_streambuf and automatically adds ANSI color codes to the output.

This is useful for colorizing terminal output with consistent color schemes.

Template Parameters
CharTCharacter type (typically char or wchar_t)
TraitsCharacter traits type
See also
Basic_color_stream_guard
make_color_guards
Examples
Stream_support/color_ostream.cpp.

Public Types

using char_type = CharT
 Character type.
 
using traits_type = Traits
 Character traits type.
 
using int_type = typename traits_type::int_type
 Integer type for character representation.
 
using pos_type = typename traits_type::pos_type
 Position type for stream positioning.
 
using off_type = typename traits_type::off_type
 Offset type for stream positioning.
 
using streambuf_type = std::basic_streambuf< char_type, traits_type >
 Type of the wrapped streambuf.
 
using string = std::basic_string< char_type >
 String type matching character type.
 

Public Member Functions

template<typename ... AnsiColors>
 Basic_color_streambuf (streambuf_type &wrapped_buf, AnsiColors... colors)
 constructs a color streambuf wrapper with one or more colors.
 
const stringcolor_code () const
 gets the current color code string.
 
void set_color_code (string color_code)
 sets a new color code.
 
bool colors_enabled () const
 checks if colors are enabled for this streambuf.
 
streambuf_typewrapped_streambuf () const
 gets the wrapped streambuf.
 

Static Public Member Functions

static bool detect_color_support (streambuf_type *buf)
 detects if the wrapped buffer supports color output.
 

Constructor & Destructor Documentation

◆ Basic_color_streambuf()

template<typename CharT , typename Traits = std::char_traits<CharT>>
template<typename ... AnsiColors>
CGAL::IO::Basic_color_streambuf< CharT, Traits >::Basic_color_streambuf ( streambuf_type wrapped_buf,
AnsiColors...  colors 
)
explicit

constructs a color streambuf wrapper with one or more colors.

Colors are automatically disabled if the wrapped buffer is not connected to a color-capable terminal (checked via isatty() and TERM variable), or if the NO_COLOR environment variable is set and non-empty.

Template Parameters
AnsiColorsVariadic list of Ansi_color values
Parameters
wrapped_bufThe underlying streambuf to wrap
colorsOne or more colors to combine (e.g., Ansi_color::Bold, Ansi_color::Red)

Member Function Documentation

◆ set_color_code()

template<typename CharT , typename Traits = std::char_traits<CharT>>
void CGAL::IO::Basic_color_streambuf< CharT, Traits >::set_color_code ( string  color_code)

sets a new color code.

Parameters
color_codeThe new color code to apply