Code Monkey home page Code Monkey logo

colors.h's Introduction

Colors

Colors is a library for color output with C++.

Example

#include <iostream>
#include "colors.hpp"

int main()
{
    colors::setColor(colors::red); // Sets the text color to be red
    colors::setBold();             // Sets the text to be bold

    std::cout << "Hello!";
    return 0;
}

Documentation

Colors is a simple library. Here are a couple functions:

setColor(black);
setBold();

These functions set your output text to be black and bold.

Here is a list of every function:

using namespace colors;    // This library is in a namespace

setColor(red, BACKGROUND); // The BACKGROUND argument
setColor(red);
setColor(green);
setColor(yellow);
setColor(blue);
setColor(magenta);
setColor(cyan);
setColor(white);
setColor(gray);

// Bright colours
setColor(brightRed);
setColor(brightGreen);
setColor(brightYellow);
setColor(brightBlue);
setColor(brightMagenta);
setColor(brightCyan);
setColor(brightWhite);

// RGB
rgb(100, 12, 30, BACKGROUND);   // Sets the background to be dark-red

// Reset all options
resetAll();

// Font-related
setBold();
setThin();
setItalic();
setUnderline();
setBlink();

// Cursor-related functions
setCursorTo(/*Row, Column*/);   // "Amount" in these functions is 1 by default
moveCursorUp(/*Amount*/);
moveCursorDown(/*Amount*/);
moveCursorLeft(/*Amount*/);
moveCursorRight(/*Amount*/);

// Reset properties
resetColors(BACKGROUND); // Resets background color
resetBoldness();         // Resets boldness
noBlink();               // No blinking text
noUnderline();           // No underline on text

// Deleting text
eraseLine();                        // Deletes text until end of line
eraseLine(TOEND);         // Deletes text until end of line (explicit)
eraseLine(TOBEGINNING);   // Deletes text until beginning of line
eraseLine(ALL);           // Deletes text on line

// Clearing terminal
eraseScreen();            // Clears from cursor to bottom of console/terminal
eraseScreen(TOEND);       // Clears from cursor to bottom of console/terminal (explicit)
eraseScreen(TOBEGINNING); // Clears from cursor to beginning of console/terminal
eraseScreen(ALL);         // Clears all
eraseScreen(CLEAR);       // Deletes lines in scrollback buffer of console/terminal

/*
Enumerations:
|-------------|----------------------------------------|---------------------------|
| Enumeration | Purpose                                | Function(s)               |
|-------------|----------------------------------------|---------------------------|
| BACKGROUND  | To apply a color to background of text | setRed(), setBlue(), etc. |
|-------------|----------------------------------------|---------------------------|
| FOREGROUND  | To apply a color to text               | setRed(), setBlue(), etc. |
|-------------|----------------------------------------|---------------------------|
| ALL         | To delete line                         | eraseLine()               |
|-------------|----------------------------------------|---------------------------|
| TOEND       | To delete until end of line            | eraseLine()               |
|-------------|----------------------------------------|---------------------------|
| TOBEGINNING | To delete until beginning of line      | eraseLine()               |
|-------------|----------------------------------------|---------------------------|
| CLEAR       | To delete terminal buffer              | eraseScreen()             |
|-------------|----------------------------------------|---------------------------|
 Other enumerations include colors,
 which are all used in the setColor() function:
 
 red
 green
 yellow
 blue
 magenta
 cyan
 white
 gray

 brightRed
 brightGreen
 brightYellow
 brightBlue
 brightMagenta
 brightCyan
 brightWhite
 brightGray
*/

That's it! Colors just makes it simpler to output text to the console, but with colors.

Note:

Not all functions are compatible with every terminal, so some are more compatible than others.

colors.h's People

Contributors

artii4 avatar viveketic avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

colors.h's Issues

enum class

If C++ version >= 11, enum class could be used instead of enum for better scope and meaning.

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.