Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Latest commit

 

History

History
61 lines (47 loc) · 2.59 KB

README.md

File metadata and controls

61 lines (47 loc) · 2.59 KB

pretty

License: MIT Downloads Version

A simple, lightweight unix console-colouring library for C++, all in one header file!

Colours

C++ map of colours

Includes the large majority of ANSI colour escape sequences. If any are missing, feel free to create an issue.

Use

A list of colour names can be found below Colours, or, alternatively, just at the top of the pretty.hpp header file.

Pretty goes under the pty namespace.

Pretty adds the reset escape sequence automically, meaning no more boilerplate CLR + str + RESET!

Say you wanted to go basic, a hello world script, for example:

#include <iostream>
// include pretty from whatever directory you store your includes in
#include "pretty.hpp"

int main() {
    std::cout << pty::paint("Hello world!", "green") << std::endl;
    // simple as that!
}

Or maybe you are working on a deadline project, and need a reusable set of sequences to avoid typing pty::paint(...) repeatedly:

// here we create the colour set, providing it as many different values as we need
pty::ColourSet clSet({"green", "bold"});
// using this colour set is easy and efficient
std::cout << clSet.apply("This is much faster!") << std::endl;

The paint function can also be used in the same way as the ColourSet constructor.

std::cout << pty::paint("I love C++!", {"yellow", "dim"}) << std::endl;

// alternatively with an array
std::vector<const char *> clrs = {"yellow", "bluebg", "underlined"};
std::cout << pty::paint("I love C!", clrs) << std::endl;

Need to save coloured text for later, or maybe remove ANSI sequences from a string?

std::string coloured = pty::paint("I'll need this later!", {"blue", "yellowbg"});

// use the 'normal(...)' function to "normalise" a string (remove ANSI escape sequences)
std::cout << pty::normal(coloured) << std::endl;
// output will be plain, uncoloured text

Testing

pretty_tests.cpp contains code for testing and checking the functionality of changes made in pretty.hpp. This is to be updated and used to verify every major addition to pretty.hpp.

Future changes

  • dim, bold and normal functions for dimming, brightening and removing escape codes from text.