Change single word color in a text with NCurses?

Hello everyone,

i would like to change a single or more word color in a text using NCurses, as follow:

The quick fox jumps over the lazy dog.

I would like to have fox in red color and lazy in yellow.

How can i do this?

Hello Amiplus,

Not familiar with NCurses, but this is what I have found to work at least with windows.

The prototype:
void SetColor(int forground = 7, int background = 1);

I used the default values here to allow me to call this function with empty (). Kind of a reset if you will.

And the function:
void SetColor(int forground, int background)
	WORD consoleColor;
	if (GetConsoleScreenBufferInfo(hStdOut, &csbi))
		consoleColor = (forground + (background * 16));
		SetConsoleTextAttribute(hStdOut, consoleColor);
}  //  End SetColor() 

After awhile I found information to allow me to set the background colour.

You will call this function with the parameters of the function as, SetColor(Foreground, Background), before each letter, work or sentence.

I know this works with windows, but I am not sure about any other operating system. I will need to do some research on NCurses.

Hope that helps,

Thank you for the reply.

I will check the links you've posted here.

It's curious how Ncurses miss the functions that you expect that should be present.
Haven't found any usefull information on the subject. Changing color in a text using ncurses is a bit difficulty.I found another console library that permit to change the color as follow: setBGcolor(red) or setFGcolor(blue). Btw i don't want to mix the two libraries (i don't know if could work).

Any other idea for ncurses?

Edit: found this really interesting. I willl resume the thread:

Last edited on
@forum admin: coul dbe possibile to reopen this thread?

Thank you very much
It seems you’re struggling a lot about colourful console programs. If you fancy them, I’m not here to discourage you, but perhaps today the number of programmers really interested in this topic is decreasing. There’s a number of graphical libraries by which you could interact with the user to a degree you’re not likely to achieve by the console, and many of them are free to use or have very permissive licenses.
I’m just saying, if you decided to give a chance to one of them, maybe you’ll like that more than Ncurses.
Registered users can post here. Sign in or register to post.