Change single word color in a text with NCurses?

Oct 27, 2017 at 9:27am
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?

Oct 27, 2017 at 10:36am
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:
1
2
3
4
5
6
7
8
9
10
11
void SetColor(int forground, int background)
{
	WORD consoleColor;
	HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	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,

Andy
Oct 27, 2017 at 2:03pm
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.
Nov 2, 2017 at 9:32am
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: http://www.cplusplus.com/forum/general/11032/

Last edited on Nov 2, 2017 at 10:23am
Nov 8, 2017 at 9:57am
@forum admin: coul dbe possibile to reopen this thread?
http://www.cplusplus.com/forum/general/11032/

Thank you very much
Nov 8, 2017 at 3:14pm
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.
Topic archived. No new replies allowed.