Template Function cif::coloured

Function Documentation

template<typename T> inline requires std::is_assignable_v< std::string_view, T > auto cif::coloured (T str, colour::colour_type fg, colour::colour_type bg=colour::colour_type::none, colour::style_type st=colour::style_type::regular)

Manipulator for coloured strings.

When writing out text to the terminal it is often useful to have some of the text colourised. But only if the output is really a terminal since colouring text is done using escape sequences an if output is redirected to a file, these escape sequences end up in the file making the real text less easy to read.

The code presented here is rather basic. It mimics the std::quoted manipulator in that it will colour a string with optionally requested colours and text style.

Example:

using namespace cif::colour;
std::cout << cif::coloured("Hello, world!", white, red, bold) << '\n';

Parameters
  • str – String to quote.

  • fg – Foreground (=text) colour to use

  • bg – Background colour to use

  • st – Text style to use