Giter Site home page Giter Site logo

backtheportal / color-console Goto Github PK

View Code? Open in Web Editor NEW

This project forked from memoryinject/color-console

0.0 0.0 0.0 6 KB

Header only c++ library for coloring and formatting console outputs

Home Page: https://www.memoryinject.io/

License: MIT License

C++ 98.25% Makefile 1.75%

color-console's Introduction

Color Console

Header only c++ library for coloring and formatting console outputs.
To more about how bash output colors and formats, please check out: https://misc.flogisoft.com/bash/tip_colors_and_formatting

This utility make it simple to add special characters for bash outputs.

Screenshots

App Screenshot

Usage/Examples

Simply include color_console.hpp to the file, then use console object to created colored and formatted outputs, a basic usage looks like this:

#include "color_console.hpp"
#inclide <iostream>

using namespace std;

int main() 
{
    // To get the formatted string 
    cout << console.get("Hello World!", { console.red, console.bold }) << endl;

    // To print the formatted string output
    console.print("Hello World!", { console.green, console.bg_red });

    return 0;
}

As you can see from the above code all the operations are done using console object.
console.get(<std::string>, <std::vector<std::string>>)
To get basic formatted string output use console.get(), it accept two arguments first one is a string to output, second one is a vector of format code special character strings which is comes with console object.
To print directly to console use console.print(), the arguments are same as console.get().

Here are all the available format codes, use them in the second arguments of cosnole.get() or console.print()

// Reset all
// Reset is a special one no need to use it, it's there for internal formatting.
console.reset

// Format
console.bold
console.dim
console.underline
console.blink
console.invert
console.hide

// Forground (text)
console.black
console.red
console.green
console.yellow
console.blue
console.magenta
console.cyan
console.gray
console.dark_gray
console.light_red
console.light_green
console.light_yellow
console.light_blue
console.light_magenta
console.light_cyan
console.white

// Background
console.bg_black
console.bg_red
console.bg_green
console.bg_yellow
console.bg_blue
console.bg_magenta
console.bg_cyan
console.bg_gray
console.bg_dark_gray
console.bg_light_red
console.bg_light_green
console.bg_light_yellow
console.bg_light_blue
console.bg_light_magenta
console.bg_light_cyan
console.bg_white

There are few preset built-in with console, it's just looks like JavaScript:

#include "color_console.hpp"

int main() 
{
    // Print to console output - presets
    // Presets does not take second argument, just the string
    console.log("Hello World!, log");
    console.info("Hello World!, info");
    console.debug("Hello World!, debug");
    console.warn("Hello World!, warn");
    console.error("Hello World!, error");

    return 0;
}

If you want to modify default format for these preset use console.set_<preset>(<std::vector<std::string>>) like this:

#include "color_console.hpp"

int main() 
{
    // Change console preset settings
    console.log("Hello World!, log before");
    console.set_log({ console.cyan, console.underline });
    console.log("Hello World!, log after");

    // Also reset the preset to default
    console.reset_log();
    console.log("Hello World!, log reset");

    // Change info preset
    console.set_info({ 
        console.light_magenta, 
        console.bold, 
        console.underline
    });
    console.info("Hello World!, info new preset");
    
    // Change debug preset
    console.set_info({ 
        console.yellow, 
        console.invert
    });
    console.debug("Hello World!, debug new preset");

    console.info("Hello World!, info new preset");
    console.debug("Hello World!, debug new preset");

    // Reset all preset back to default
    console.reset_all();
    console.info("Hello World!, info reset");
    console.debug("Hello World!, debug reset");

    return 0;
}

All these examples can be found on color_console_example.cpp file.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.