Home

Awesome

rang Build Status Build status codecov Download

Colors for your Terminal.

rang-demo

<details> <summary>Windows Demo</summary>

rang-windows-demo

</details>

Example usage

#include "rang.hpp"

using namespace std;
using namespace rang;

int main()
{
    cout << "Plain old text"
         << style::bold << "Rang styled text!!"
         << style::reset << endl;
}

Dependencies

rang only depends on C++ standard library, unistd.h system header on unix and windows.h & io.h system headers on windows based systems. In other words, you don't need any 3rd party dependencies.

Installation

rang is a single header-only library. Put rang.hpp in the include folder directly into the project source tree or somewhere reachable from your project.

Or, if you use the conan package manager, follow these steps:

  1. Add a reference to rang to the requires section of your project's conanfile.txt file:

     [requires]
     rang/3.1.0@rang/stable
    
  2. Run conan's install command:

     conan install
    

How to use

Rang uses iostream objects - cout/clog/cerr to apply attributes to output text. Since rang aims to support both windows and unix like systems, it takes care of the os specific details and tries to provide a uniform interface. Due to incompatiblities b/w different OS versions, not all kinds of attributes are supported on every system so rang will try to skip the ones which might produce garbage(instead of pushing random ANSI escape codes on your streams). Detection of tty is also handled internally so you don't need to check if application user might redirect output to a file.

Need support for non-ansi terminals? Check out Termdb which supports virtually all terminals and their capablities.

Apart from setting text attributes, you can also ask rang to override its default behaviour through these methods -

void rang::setControlMode(rang::control);

where rang::control takes

void rang::setWinTermMode(rang::winTerm);

where rang::winTerm takes

Supported attributes with their compatiblity are listed below -

Text Styles:

CodeLinux/Win/OthersOld Win
rang::style::boldyesyes
rang::style::dimyesno
rang::style::italicyesno
rang::style::underlineyesno
rang::style::blinknono
rang::style::rblinknono
rang::style::reversedyesyes
rang::style::concealmaybeyes
rang::style::crossedyesno

Text Color:

CodeLinux/Win/OthersOld Win
rang::fg::blackyesyes
rang::fg::redyesyes
rang::fg::greenyesyes
rang::fg::yellowyesyes
rang::fg::blueyesyes
rang::fg::magentayesyes
rang::fg::cyanyesyes
rang::fg::grayyesyes

Background Color:

CodeLinux/Win/OthersOld Win
rang::bg::blackyesyes
rang::bg::redyesyes
rang::bg::greenyesyes
rang::bg::yellowyesyes
rang::bg::blueyesyes
rang::bg::magentayesyes
rang::bg::cyanyesyes
rang::bg::grayyesyes

Bright Foreground Color:

CodeLinux/Win/OthersOld Win
rang::fgB::blackyesyes
rang::fgB::redyesyes
rang::fgB::greenyesyes
rang::fgB::yellowyesyes
rang::fgB::blueyesyes
rang::fgB::magentayesyes
rang::fgB::cyanyesyes
rang::fgB::grayyesyes

Bright Background Color:

CodeLinux/Win/OthersOld Win
rang::bgB::blackyesyes
rang::bgB::redyesyes
rang::bgB::greenyesyes
rang::bgB::yellowyesyes
rang::bgB::blueyesyes
rang::bgB::magentayesyes
rang::bgB::cyanyesyes
rang::bgB::grayyesyes

Reset Styles/Colors:

CodeLinux/Win/OthersOld Win
rang::style::resetyesyes
rang::fg::resetyesyes
rang::bg::resetyesyes

My terminal is not detected/gets garbage output!

Check your env variable TERM's value. Then open an issue here and make sure to mention TERM's value along with your terminal name.

Redirecting cout/cerr/clog rdbuf?

Rang doesn't interfere if you try to redirect cout/cerr/clog to somewhere else and leaves the decision to the library user. Make sure you've read this conversation and check out the example code here.