Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srilakshmikanthanp/libansi
ANSI escape sequence for c++, use this library for text formatting tasks with standard ANSI escape sequence!
https://github.com/srilakshmikanthanp/libansi
ansi ansi-escape-sequence manipulators
Last synced: about 2 months ago
JSON representation
ANSI escape sequence for c++, use this library for text formatting tasks with standard ANSI escape sequence!
- Host: GitHub
- URL: https://github.com/srilakshmikanthanp/libansi
- Owner: srilakshmikanthanp
- License: mit
- Created: 2021-05-03T10:08:36.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T04:41:08.000Z (about 1 year ago)
- Last Synced: 2024-10-27T00:52:27.976Z (2 months ago)
- Topics: ansi, ansi-escape-sequence, manipulators
- Language: C++
- Homepage: https://srilakshmikanthanp.github.io/libansi/docs/html/
- Size: 527 KB
- Stars: 12
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
libansi
ANSI escape sequence
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
## 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,
~~~cpp
// 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:**
~~~cpp
// 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:**
~~~cpp
// 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:**
~~~cpp
// 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`
~~~cpp
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]("https://srilakshmikanthanp.github.io/libansi/docs/html")_
## 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](https://github.com/srilakshmikanthanp/libansi)