Skip to content

moshiba/ansi-escape

Repository files navigation

Ansi-Escape GitHub GitHub release (latest SemVer including pre-releases)

GitHub code size in bytes Codacy Badge

ANSI escape codes wrapped in C++ string streams.

It's everything you need for advanced terminal control, wrapped in light headers ready for inclusion.

Table of Contents

About Ansi-Escape

Ansi-Escape, or AESC, is an effort to wrap common terminal controls and colors for prettier terminal output. It is built and tested on macOS, but probably will work in other *NIX systems as well.

To maximize compatibility, we choose to support C++11, with CMake-3.9 as a build dependency.

Quickstart

AESC implemented most ANSI escape sequences, including text coloring and cursor controlling

there are example codes in the examples/ directory, see Install for more information.

Find detailed list of available APIs at docs and wikipedia

Simple example of text coloring

#include <iostream>
#include "aesc.hpp"
using namespace std;
using aesc::color;

int main() {
    cout << red << " foreground is red" << endl;

    cout << bright::red << bright::background::cyan
         << " background bright cyan, foreground bright red" << endl;

    cout << aesc::color256::RGB::foreground(2, 3, 0) << "256 color RGB test sequence"
         << endl;

    cout << aesc::truecolor::RGB::foreground(130, 250, 0)
         << "24-bit true color RGB test sequence" << aesc::render::reset << endl;
}

Simple example of cursor control

See the provided example at examples/show_color.cpp

Install

Install it with Homebrew, or build it using CMake

Install with Homebrew

brew tap hsuantinglu/utils
brew install ansi-escape

Build with CMake

CMake is the official build system. At least version 3.9 is needed.

mkdir build; cd build/

# Config and build
cmake .. && make showcolor

# execute example
./examples/showcolor