All Projects → ikalnytskyi → Termcolor

ikalnytskyi / Termcolor

Licence: other
Termcolor is a header-only C++ library for printing colored messages to the terminal. Written just for fun with a help of the Force.

Projects that are alternatives of or similar to Termcolor

Consola
Elegant Console Logger for Node.js and Browser 🐨
Stars: ✭ 3,461 (+549.34%)
Mutual labels:  terminal, console, fancy
Colorette
Easily set the color and style of text in the terminal.
Stars: ✭ 1,047 (+96.44%)
Mutual labels:  terminal, console, colors
Termenv
Advanced ANSI style & color support for your terminal applications
Stars: ✭ 555 (+4.13%)
Mutual labels:  terminal, console, colors
Colorful
Terminal string styling done right, in Python 🐍 🎉
Stars: ✭ 456 (-14.45%)
Mutual labels:  terminal, console, colors
Bcal
🔢 Storage and general-purpose calculator
Stars: ✭ 329 (-38.27%)
Mutual labels:  terminal, console
Tqdm
A Fast, Extensible Progress Bar for Python and CLI
Stars: ✭ 20,632 (+3770.92%)
Mutual labels:  terminal, console
Console
The Hoa\Console library.
Stars: ✭ 354 (-33.58%)
Mutual labels:  terminal, console
Mle
Flexible terminal-based text editor (C)
Stars: ✭ 378 (-29.08%)
Mutual labels:  terminal, console
Csconsoleformat
.NET C# library for advanced formatting of console output [Apache]
Stars: ✭ 296 (-44.47%)
Mutual labels:  terminal, console
Stig
TUI and CLI for the BitTorrent client Transmission
Stars: ✭ 360 (-32.46%)
Mutual labels:  terminal, console
Upterm
A terminal emulator for the 21st century.
Stars: ✭ 19,441 (+3547.47%)
Mutual labels:  terminal, console
Cfiles
A ncurses file manager written in C with vim like keybindings
Stars: ✭ 319 (-40.15%)
Mutual labels:  terminal, console
Pastel
A command-line tool to generate, analyze, convert and manipulate colors
Stars: ✭ 3,742 (+602.06%)
Mutual labels:  terminal, colors
Nord Dircolors
An arctic, north-bluish clean and elegant dircolors theme.
Stars: ✭ 328 (-38.46%)
Mutual labels:  terminal, colors
Terminal Icons
A PowerShell module to show file and folder icons in the terminal
Stars: ✭ 303 (-43.15%)
Mutual labels:  terminal, console
Lazykube
⎈ The lazier way to manage kubernetes.
Stars: ✭ 369 (-30.77%)
Mutual labels:  terminal, console
Terminology
The best terminal emulator based on the Enlightenment Foundation Libraries
Stars: ✭ 440 (-17.45%)
Mutual labels:  terminal, console
Yaspin
A lightweight terminal spinner for Python with safe pipes and redirects 🎁
Stars: ✭ 413 (-22.51%)
Mutual labels:  terminal, console
Pulsemixer
CLI and curses mixer for PulseAudio
Stars: ✭ 441 (-17.26%)
Mutual labels:  terminal, console
Nestjs Console
A nestjs module that provide a cli to your application.
Stars: ✭ 284 (-46.72%)
Mutual labels:  terminal, console

Termcolor

.. image:: docs/_static/example.png :alt: termcolor in action :align: left

.. -- inclusion-marker-for-sphinx-docs --

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 is used such terminals (most *nix systems, including Linux and Mac OS).

.. note::

On Windows, Windows API_ is used instead of escape codes but some limitations are applied (not everything is supported). That's why it's recommended to enter virtual terminal processing_ mode and set TERMCOLOR_USE_ANSI_ESCAPE_SEQUENCES macro to trick termcolor to use ANSI color codes.

.. _virtual terminal processing: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

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

.. _Termcolor: https://github.com/ikalnytskyi/termcolor .. _the Force: https://starwars.wikia.com/wiki/The_Force .. _ANSI color formatting: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors .. _Windows API: https://docs.microsoft.com/en-us/windows/console/setconsoletextattribute

Installation

How to use?

It's very easy to use. The idea is built upon C++ stream manipulators. Typical «Hello World» application looks like this:

.. code:: c++

#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.

.. code:: c++

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

Correct version of the code above should look like this:

.. code:: c++

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

.. code:: c++

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

will print «unicorn» using default color, not red. In order to change this behaviour one can use termcolor::colorize manipulator that enforce 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 changes some text style (bold, underline, etc);
  • control, which changes termcolor's behaviour.

Also, there are color manipulators for 16 colors, 256 colors and true colors_ palettes.

.. note::

While termcolor supports true color, it's required for the terminal emulator you use to run your software to support true color too. So please ensure it's supported before filing an issue.

.. _16 colors: https://en.wikipedia.org/wiki/Color_depth#4-bit_color .. _256 colors: https://en.wikipedia.org/wiki/Color_depth#8-bit_color .. _true colors: https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)

Foreground manipulators .......................

16 colors


#. ``termcolor::grey``
#. ``termcolor::red``
#. ``termcolor::green``
#. ``termcolor::yellow``
#. ``termcolor::blue``
#. ``termcolor::magenta``
#. ``termcolor::cyan``
#. ``termcolor::white``
#. ``termcolor::bright_grey``
#. ``termcolor::bright_red``
#. ``termcolor::bright_green``
#. ``termcolor::bright_yellow``
#. ``termcolor::bright_blue``
#. ``termcolor::bright_magenta``
#. ``termcolor::bright_cyan``
#. ``termcolor::bright_white``

256 colors

#. termcolor::color<256_COLOR_CODE>

true colors


#. ``termcolor::color<RED, GREEN, BLUE>``


Background manipulators
.......................

16 colors
`````````

#. ``termcolor::on_grey``
#. ``termcolor::on_red``
#. ``termcolor::on_green``
#. ``termcolor::on_yellow``
#. ``termcolor::on_blue``
#. ``termcolor::on_magenta``
#. ``termcolor::on_cyan``
#. ``termcolor::on_white``
#. ``termcolor::on_bright_grey``
#. ``termcolor::on_bright_red``
#. ``termcolor::on_bright_green``
#. ``termcolor::on_bright_yellow``
#. ``termcolor::on_bright_blue``
#. ``termcolor::on_bright_magenta``
#. ``termcolor::on_bright_cyan``
#. ``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)

#. termcolor::bold #. termcolor::dark #. termcolor::italic #. termcolor::underline #. termcolor::blink #. termcolor::reverse #. termcolor::concealed #. termcolor::crossed

Control manipulators ....................

(Windows API does not support these manipulators)

#. termcolor::colorize #. termcolor::nocolorize

Caveats

#. On Windows, due to internal usage of <windows.h>, global namespace could be polluted with min/max macros. If such effect is desireable, please consider using #define NOMINMAX before #include <termcolor.hpp>.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].