0.0.0 • Published 11 years ago

colors.cc v0.0.0

Weekly downloads
3
License
-
Repository
github
Last release
11 years ago

colors.cc

colors.cc is a library for quickly adding color codes to your C++ strings for terminal output.

Usage

To use colors.cc, simply npm install colors.cc and #require "colors.cc" as colors

colors.use() takes 3 parameters and returns a std::string;

ParameterTypeDesctription
strstd::stringThe string you wish to colorise
foreintforeground color
backintbackground color

The colors are represented by numbers 0 - 15 with -1 as the default, you can use the enum values to represent colors or the numbers as specified in the table below:

ColorEnumNo
defaultCC_DEFAULT-1
blackCC_BLACK0
redCC_RED1
greenCC_GREEN2
brownCC_BROWN3
blueCC_BLUE4
magantaCC_MAGENTA5
cyanCC_CYAN6
grayCC_GRAY7
dark_grayCC_DARK_GRAY8
light_redCC_LIGHT_RED9
light_greenCC_LIGHT_GREEN10
yellowCC_YELLOW11
light_blueCC_LIGHT_BLUE12
light_magentaCC_LIGHT_MAGENTA13
light_cyanCC_LIGHT_CYAN14
whiteCC_WHITE = 1515

EXAMPLE

#include <iostream>
#include <string>

#require "colors.cc" as colors

using namespace std;

int main( int argc, char* argv[] ) {

	string a = "Hello colorful world";

	cout << colors.use( a, colors.grey , colors.magenta ) << endl;
	cout << colors.use( "single test", colors.cyan, colors.bg ) << endl;
	cout << colors.use( " single test ", colors.black, colors.blue) << endl;

	return 0;
}

LICENSE

BSD LICENSE

Copyright (c) 2013, Divan Visagie All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Divan Visagie. 4. Neither the name of Divan Visagie nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY Divan Visagie ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Divan Visagie BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.