FE 0.9.0
Header-only C++ frontend library
Loading...
Searching...
No Matches
fe::term Namespace Reference

Lightweight stream-based terminal colors for diagnostics and CLI output. More...

Enumerations

enum class  Mode {
  Auto ,
  Never ,
  Always
}
 Controls whether color escape sequences are emitted. More...
enum class  FG {
  Black ,
  Red ,
  Green ,
  Yellow ,
  Blue ,
  Magenta ,
  Cyan ,
  Gray ,
  Grey = Gray ,
  Reset
}
 Foreground colors that can be streamed into an std::ostream. More...

Functions

Mode mode () noexcept
 Returns the current terminal color mode.
void set_mode (Mode m) noexcept
 Overrides the current terminal color mode.
std::ostream & operator<< (std::ostream &os, FG color)
 Streams the ANSI escape sequence for color when colors are enabled for os.

Detailed Description

Lightweight stream-based terminal colors for diagnostics and CLI output.

Include fe/term.h and stream a fe::term::FG value into an std::ostream:

std::cerr << fe::term::FG::Red << "error: " << fe::term::FG::Reset << "unexpected token\n";

The current behavior is controlled via fe::term::Mode and can be overridden with fe::term::set_mode. In fe::term::Mode::Auto, colors are emitted only for std::cout, std::cerr, std::clog, or streams sharing those buffers when they refer to terminals. FE also respects the common environment conventions NO_COLOR, CLICOLOR=0, and CLICOLOR_FORCE (unless it is set to 0).

Enumeration Type Documentation

◆ FG

enum class fe::term::FG
strong

Foreground colors that can be streamed into an std::ostream.

Enumerator
Black 
Red 
Green 
Yellow 
Blue 
Magenta 
Cyan 
Gray 
Grey 
Reset 

Definition at line 48 of file term.h.

◆ Mode

enum class fe::term::Mode
strong

Controls whether color escape sequences are emitted.

Enumerator
Auto 
Never 
Always 

Definition at line 41 of file term.h.

Function Documentation

◆ mode()

Mode fe::term::mode ( )
inlinenoexcept

Returns the current terminal color mode.

Definition at line 183 of file term.h.

◆ operator<<()

std::ostream & fe::term::operator<< ( std::ostream & os,
FG color )
inline

Streams the ANSI escape sequence for color when colors are enabled for os.

Definition at line 189 of file term.h.

◆ set_mode()

void fe::term::set_mode ( Mode m)
inlinenoexcept

Overrides the current terminal color mode.

Definition at line 186 of file term.h.