https://github.com/tudeorangbiasa/ansicolorcpp
Simple ANSI escape color code to print colored text or background in terminal using c++
https://github.com/tudeorangbiasa/ansicolorcpp
ansi cpp
Last synced: 9 days ago
JSON representation
Simple ANSI escape color code to print colored text or background in terminal using c++
- Host: GitHub
- URL: https://github.com/tudeorangbiasa/ansicolorcpp
- Owner: TudeOrangBiasa
- Created: 2025-02-08T02:55:32.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-02-08T03:43:36.000Z (over 1 year ago)
- Last Synced: 2025-06-07T13:43:30.817Z (about 1 year ago)
- Topics: ansi, cpp
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ANSI Color CPP
This project demonstrates the usage of ANSI escape codes to print colored text in the terminal using C++. It includes functions to set foreground and background colors, as well as text formatting options like bold, italic, and underline.
## Files
- `example/example.cpp`: Example usage of the color functions.
- `color.cpp`: Implementation of the color functions.
- `color.h`: Header file declaring the color functions.
## Usage
1. **Clone the repository:**
```sh
git clone https://github.com/TudeOrangBiasa/ansicolorcpp.git
cd ansiColorCPP
```
2. **Compile the code:**
```sh
g++ -Wall -std=c++11 color.cpp example/example.cpp -o ansi_demo
```
3. **Run the example:**
```sh
./ansi_demo
```
## Functions
### Text Formatting
- `reset()`: Resets all text formatting.
- `bold()`: Makes text bold.
- `faint()`: Makes text faint.
- `italic()`: Makes text italic.
- `underline()`: Underlines text.
- `inverse()`: Inverts text color.
- `strikethrough()`: Strikes through text.
### Foreground Colors
- `fgBlack()`, `fgRed()`, `fgGreen()`, `fgYellow()`, `fgBlue()`, `fgMagenta()`, `fgCyan()`, `fgWhite()`
- `fgBrightBlack()`, `fgBrightRed()`, `fgBrightGreen()`, `fgBrightYellow()`, `fgBrightBlue()`, `fgBrightMagenta()`, `fgBrightCyan()`, `fgBrightWhite()`
### Background Colors
- `bgBlack()`, `bgRed()`, `bgGreen()`, `bgYellow()`, `bgBlue()`, `bgMagenta()`, `bgCyan()`, `bgWhite()`
- `bgBrightBlack()`, `bgBrightRed()`, `bgBrightGreen()`, `bgBrightYellow()`, `bgBrightBlue()`, `bgBrightMagenta()`, `bgBrightCyan()`, `bgBrightWhite()`
## Example
```cpp
#include
#include "color.h"
int main() {
std::cout << fgRed() << "This is red text" << reset() << std::endl;
std::cout << bgGreen() << "This is text with green background" << reset() << std::endl;
return 0;
}
```
## Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.