Giter VIP home page Giter VIP logo

color_ostream's Introduction

color

中文说明
Partly learned from: colored-cout
release cpp chat

usage

Project is header-only,you can use it via directly include it(at least C++11)
Let's see, how convenient is our header:
all you need to do is changing cout to rd_cout

std basic color 256 color true color
std::cout color_ostream::rd_cout color_ostream::rd256_cout color_ostream::rdtrue_cout
std::wcout color_ostream::rd_wcout color_ostream::rd256_wcout color_ostream::rdtrue_wcout
std::cerr color_ostream::rd_cerr color_ostream::rd256_cerr color_ostream::rdtrue_cerr
std::wcerr color_ostream::rd_wcerr color_ostream::rd256_wcerr color_ostream::rdtrue_wcerr
std::clog color_ostream::rd_clog color_ostream::rd256_clog color_ostream::rdtrue_clog
std::wclog color_ostream::rd_wclog color_ostream::rd256_wclog color_ostream::rdtrue_wclog

note

support for 256 color and true color needs corresponding support in terminal,such as Windows terminal, Visual studio debug console, MacOS terminal.app, iterm2 all support 256 color.

sample

sample

example file

hello.cpp:

//hello.cpp
#include "color_ostream.h"

using namespace color_ostream;

int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {
    rd_wcout.imbue(std::locale(std::locale(),"",LC_CTYPE));
    rd_wcout << L"Hello world\n";
    rd_wcout << L"Hola Mundo\n";
    rd_wcout << L"Bonjour le monde\n";

    rd256_wcout << L"\n256 color" << std::endl;
    rd256_wcout << L"Hello world\n";
    rd256_wcout << L"Hola Mundo\n";
    rd256_wcout << L"Bonjour le monde\n";

    rdtrue_wcout << L"\ntrue color" << std::endl;
    rdtrue_wcout << L"Hello world\n";
    rdtrue_wcout << L"Hola Mundo\n";
    rdtrue_wcout << L"Bonjour le monde\n";
    return 0;
}

color.cpp:

//color.cpp
#include "color_ostream.h"

using namespace color_ostream;
using namespace std;

int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {
    std::cout << clr::red     << " red "
              << clr::yellow  << " yellow "
              << clr::green   << " green "
              << clr::cyan    << " cyan "
              << clr::blue    << " blue "
              << clr::magenta << " magenta "
              << clr::grey    << " grey "
              << clr::white   << " white "
              << clr::reset   << " reset\n";
    std::cout << clr::red     << clr::on_cyan    << " red "
              << clr::yellow  << clr::on_blue    << " yellow "
              << clr::green   << clr::on_magenta << " green "
              << clr::cyan    << clr::on_red     << " cyan "
              << clr::blue    << clr::on_yellow  << " blue "
              << clr::magenta << clr::on_green   << " magenta "
              << clr::grey    << clr::on_white   << " grey "
              << clr::white   << clr::on_grey    << " white "
              << clr::reset                      << " reset\n";
}

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.