Giter Site home page Giter Site logo

termcolor-c's Introduction

termcolor-c

A header-only ANSI C library for writing colored text to the terminal, based on Termcolor for C++.

screenshot

Like Termcolor, it uses ANSI escape codes to modify text attributes. This should work on most terminals, at least for POSIX-like systems. Note that unlike Termcolor, Windows is not yet supported here.

Usage

Add termcolor-c.h to your project and #include it. The library is also installable using clib.

The idea behind termcolor, which is mimicked in termcolor-c, is to manipulate the underlying stream to which text is written. As an example:

#include <stdio.h>
#include "termcolor-c.h"

int main(int argc, char** argv) {
    fputs("Hello, colorful world\n", text_red(stdout));
    reset_colors(stdout);
    return 0;
}

If you compile this and run it, you'll find that "Hello, colorful world" has been printed to STDOUT in red. Note that if you don't call reset_colors, text in the terminal will continue to be red even after the program has finished executing.

Supported attributes

Foreground colors

  • text_gray and text_grey
  • text_red
  • text_green
  • text_yellow
  • text_blue
  • text_magenta
  • text_cyan
  • text_white

Background colors

  • background_grey and background_gray
  • background_red
  • background_green
  • background_yellow
  • background_blue
  • background_magenta
  • background_cyan
  • background_white

Text style

  • text_bold
  • text_dark
  • text_underline
  • text_blink (may not be supported in many terminals)
  • text_reverse (may not be supported in many terminals)
  • text_concealed (may not be supported in many terminals)

License

Licensed under the terms of the 2-clause "simplified" BSD license. See LICENSE.

termcolor-c's People

Contributors

ararslan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.