npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

termcolor.cxx

v2.2024.8

Published

Termcolor is a header-only C++ library for printing colored messages to the terminal. Written just for fun with a help of the Force; Ihor Kalnytskyi (2013).

Readme

Termcolor

termcolor in action

Termcolor is a header-only C++ library for printing colored messages to the terminal. Written just for fun with a help of the Force. Termcolor uses ANSI color formatting, so you can use it on every system that supports such terminals (most *nix systems, including Linux and macOS).

Note

On Windows, the Windows API is used instead of escape codes but some limitations are applied (not everything is supported). That's why it's recommended to enable virtual terminal processing mode and set the TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES macro to trick termcolor into using ANSI color codes.

It’s licensed under the BSD (3-clause) License. That basically means: do whatever you want as long as the copyright sticks around.


Installation

Run:

$ npm i termcolor.cxx

And then include termcolor.hpp as follows:

// main.cxx
#include <termcolor.hpp>  // or, termcolor/termcolor.hpp

int main() { /* ... */ }

Finally, compile while adding the path node_modules/termcolor.cxx to your compiler's include paths.

$ clang++ -I./node_modules/termcolor.cxx main.cxx  # or, use g++
$ g++     -I./node_modules/termcolor.cxx main.cxx

You may also use a simpler approach with the cpoach tool, which automatically adds the necessary include paths of all the installed dependencies for your project.

$ cpoach clang++ main.cxx  # or, use g++
$ cpoach g++     main.cxx
  • You can also use vcpkg to install the library:

    $ vcpkg install termcolor
  • Or if you are on macOS, you can use Homebrew:

    $ brew install termcolor
  • For up-to-date information about existing packages, refer to the following picture:

    Packaging Status


How to use?

It’s very easy to use. The idea is built upon C++ stream manipulators. A typical “Hello World” application looks like this:

#include <iostream>
#include <termcolor/termcolor.hpp>

int main(int /*argc*/, char** /*argv*/)
{
    std::cout << termcolor::red << "Hello, ";                   // 16 colors
    std::cout << termcolor::color<100> << "Colorful ";          // 256 colors
    std::cout << termcolor::color<211, 54, 130> << "World!";    // true colors
    std::cout << std::endl;
    return 0;
}

The application above prints a string using different colors. There is one caveat though: you must not forget to reset colors, otherwise they will be applied to other prints as well.

std::cout << termcolor::red << "Hello, Colorful World!" << std::endl;
std::cout << "I'm RED too!" << std::endl;

The correct version of the code above should look like this:

std::cout << termcolor::red << "Hello, Colorful World!" << termcolor::reset << std::endl;
std::cout << termcolor::reset << "Here I'm!" << std::endl;

By default, Termcolor ignores any colors for non-TTY streams (e.g. std::stringstream), so the following snippet:

std::stringstream ss;
ss << termcolor::red << "unicorn";
std::cout << ss.str();

will print “unicorn” using the default color, not red. To change this behavior, use the termcolor::colorize manipulator, which enforces colors no matter what.


What manipulators are supported?

The manipulators are divided into four groups:

  • foreground, which changes text color
  • background, which changes text background color
  • attributes, which change text style (bold, underline, etc.)
  • control, which change termcolor’s behavior

There are also color manipulators for 16 colors, 256 colors, and true colors palettes.

Note

While termcolor supports true color, the terminal emulator you use must also support true color. Please ensure it is supported before filing an issue.


Foreground manipulators

16 colors

  1. termcolor::grey
  2. termcolor::red
  3. termcolor::green
  4. termcolor::yellow
  5. termcolor::blue
  6. termcolor::magenta
  7. termcolor::cyan
  8. termcolor::white
  9. termcolor::bright_grey
  10. termcolor::bright_red
  11. termcolor::bright_green
  12. termcolor::bright_yellow
  13. termcolor::bright_blue
  14. termcolor::bright_magenta
  15. termcolor::bright_cyan
  16. termcolor::bright_white

256 colors

  • termcolor::color<256_COLOR_CODE>

True colors

  • termcolor::color<RED, GREEN, BLUE>

Background manipulators

16 colors

  1. termcolor::on_grey
  2. termcolor::on_red
  3. termcolor::on_green
  4. termcolor::on_yellow
  5. termcolor::on_blue
  6. termcolor::on_magenta
  7. termcolor::on_cyan
  8. termcolor::on_white
  9. termcolor::on_bright_grey
  10. termcolor::on_bright_red
  11. termcolor::on_bright_green
  12. termcolor::on_bright_yellow
  13. termcolor::on_bright_blue
  14. termcolor::on_bright_magenta
  15. termcolor::on_bright_cyan
  16. termcolor::on_bright_white

256 colors

  • termcolor::on_color<256_COLOR_CODE>

True colors

  • termcolor::on_color<RED, GREEN, BLUE>

Attribute manipulators

(Windows API does not support these manipulators except for underline)

  1. termcolor::bold
  2. termcolor::dark
  3. termcolor::italic
  4. termcolor::underline
  5. termcolor::blink
  6. termcolor::reverse
  7. termcolor::concealed
  8. termcolor::crossed

Control manipulators

(Windows API does not support these manipulators)

  1. termcolor::colorize
  2. termcolor::nocolorize

Caveats

  1. On Windows, due to internal usage of <windows.h>, the global namespace may be polluted with min/max macros. If such an effect is undesirable, consider using:

    #define NOMINMAX
    #include <termcolor.hpp>

SRC ORG