Giter Site home page Giter Site logo

sgr_macro's Introduction

SGR_MACRO

This is a header-only library for C and C++ to easily control string color and style on terminal supporting ANSI color sequence.

Usage

Setup

Copy the header file sgr_macro.h to your project, and write:

#include "sgr_macro.h"

Code

SGR(code) and SGR(code1, code2, ...) will be expanded to a string literal.

Supported codes are listed below:

  • FG_*
    • Foreground color.
    • Supported colors are: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, and WHITE.
  • BG_*
    • Background color.
    • Same colors as FG_* are supported.
  • RESET: Reset all styles.
  • BOLD: Bold.
  • NO_BOLD: Stop bold font.
  • UNDERLINE: Underline.
  • NO_UNDERLINE: Stop underline.
  • BLINK: Blink the text.
  • NO_BLINK: Stop blink text.
  • NEGATIVE: Swap bg color and fg color.
  • NO_NEGATIVE: Stop swapping bg color and fg color.

Examples

  • SGR(BOLD) will be expanded to "\033[1m".
  • SGR(RESET, FG_RED, BOLD) will be expanded to "033[0;31;1m".

See also: examples/sample.c.

Customize

Add #define SGR_FOOBAR "999" before #include "sgr_macro.h", then you can use SGR(FOOBAR) and it will be expanded into "\033[999m".

To see the list of available codes, visit https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters (referred 2017-12-07).

Macro definitions

This library defines only macros, all of them have prefix SGR_.

Release

1.0 (2017-12-07)

Initial release.

License

Licensed under MIT license.

See LICENSE-MIT.txt or https://opensource.org/licenses/MIT.

sgr_macro's People

Stargazers

 avatar  avatar

Watchers

 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.