Giter Club home page Giter Club logo

libansi's Introduction


libansi

ANSI escape sequence
Explore the docs »
Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Contributing
  5. License
  6. Contact

About The Project

This is a wrapper over ANSI escape sequence for color, cursor movementand etc.

Getting Started

Installation

It's a Header only library so just download libansi.hpp

Usage

Usage is very easy this library uses manipulators to make work easy, if you are using windows you may need to enable virtual terminal processing,

// sample to enable
int EnableVirtualTerminalProcessing()
{
  HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);

  if (StdOut != INVALID_HANDLE_VALUE)
  {
    DWORD mode = 0;
    if (GetConsoleMode(StdOut, &mode))
    {
      mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
      if (SetConsoleMode(StdOut, mode))
      {
        return 0;
      }
    }
  }

  return GetLastError();
}

3 and 4 bit colors:

// background
std::cout << libansi::bg_yellow;
// foreground
std::cout << libansi::fg_blue;
// output
std::cout << "Blue on yellow";
// reset
std::cout << libansi::reset;

8 bit color:

// background
std::cout << libansi::bg_color(157);
// foreground
std::cout << libansi::fg_color(100);
// outpt
std::cout << "8 bit color";
// reset
std::cout << libansi::reset;

24 bit color:

// background
std::cout << libansi::bg_color(0, 255, 0);
// foreground
std::cout << libansi::fg_color(0, 0, 255);
// output
std::cout << "24 bit color";
// reset
std::cout << libansi::reset;

to string:

You can easily convert this manipulators to string by using libansi::str

std::string bg_yellow = libansi::str(libansi::bg_yellow);
std::string fg_blue   = libansi::str(libansi::fg_blue);
std::string reset     = libansi::str(libansi::reset);

std::cout << bg_yelow;
// foreground
std::cout << fg_blue;
// output
std::cout << "Blue on Yellow";
// reset
std::cout << reset;

For more examples, please refer to the Documentation

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/srilakshmikanthanp/libansi

libansi's People

Contributors

srilakshmikanthanp avatar jgoossen851 avatar apivovarov avatar miropalmu 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.