lmyqqded
lmyqqded

Reputation: 5

Is there a way to change color without outputting the ANSI escape sequence in C++?

I am on android, using termux and clang. I am trying to do something like the echo command but with colored output (for fun.)

I have this code, and the normal outputting works, but I'm confused on how to change color without the ANSI escape sequence being outputted with the text?

This is my code:

#define RESET "\033[0m"
#include <string>
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
for (int i = 2; i < argc; ++i) {
cout << argv[1] << argv[i] << " " << RESET;
}
}

Upvotes: 0

Views: 410

Answers (1)

Loki Astari
Loki Astari

Reputation: 264381

You will need to use a library that understands how to write to the terminal.

You could look at ncurses.

Its been a while since I did any of this stuff but if you want to draw (term used loosely) on the terminal this is a simple library that abstracts away particular terminal devices.

It is used by people writing OS installers who don't know what graphics software is available and so must write user interfaces that work in the terminal.

Here is a getting stared guide:

Hello World
ncurses Colored Text
Getting Started Guid

Upvotes: 1

Related Questions