Coloured texted in console/terminal
Using ncurses in C++, how would I colour my text in a console/terminal without breaking MinGW support? Are there any other libraries that can do this? I know that you can do it with ASCII characters, but this isn't fully supported开发者_Python百科. I don't want to use the Windows API.
The discussion in the other answer is regarding Windows, so for the benefit of Win readers, I'm leaving this answer even though it is not cross-platform.
The Old New Thing blog covers some of the Win32 API that can be used to change text color in the console. See FillConsoleOutputAttribute and Console Screen Buffers.
Your reference to mingw implies that you expect this to work in a Windows Cmd window. Unfortunately the Cmd window doesn't support color, except globally for the whole window.
I can't speak for NCurses, but I have used PDCurses to do color under winXP/MSVC 6, WIN7/MSVC 2010 in a console application.
精彩评论