Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors dont work on a normal console window #1794

Closed
auth12 opened this issue Jul 27, 2020 · 8 comments
Closed

Colors dont work on a normal console window #1794

auth12 opened this issue Jul 27, 2020 · 8 comments
Labels

Comments

@auth12
Copy link

auth12 commented Jul 27, 2020

fmt::print(fg(fmt::color::green) | fmt::emphasis::bold, "$> ");

example output :
�[1m�[38;2;000;128;000m$> �[0m27ec3180000 �[1m�[38;2;000;128;000m$> �[0mcurrent server version 0.1.0. �[1m�[38;2;000;128;000m$> �[0m1:FpK4]E-.4i->0.1.0 2

@foonathan
Copy link
Contributor

What console/terminal emulator are you using? On what OS?

@auth12
Copy link
Author

auth12 commented Jul 27, 2020

Windows, I guess fmt doesn't support windows console colors, I have to use SetConsoleTextAttribute in order to print colored text

@auth12 auth12 closed this as completed Jul 27, 2020
@vitaut vitaut added the invalid label Oct 25, 2020
@DHowett
Copy link

DHowett commented Feb 5, 2021

Sorry, I know this is an old thread. To get control sequences working in the Windows console, you will want to SetConsoleMode(...) to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on the output handle. This is not the default for compatibility reasons (sorry!)

@rebb
Copy link

rebb commented Jul 5, 2021

Sorry, I know this is an old thread. To get control sequences working in the Windows console, you will want to SetConsoleMode(...) to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on the output handle. This is not the default for compatibility reasons (sorry!)

Should this work on a Windows 7 system ?
I tried to do it using the following snippet, but it didn't help - control sequences still just print directly.
I wonder how the colorama library for Python handles this.

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = 0;
GetConsoleMode(hOut, &dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(hOut, dwMode);

@vitaut
Copy link
Contributor

vitaut commented Jul 5, 2021

Color support is available starting from Windows 10: https://en.wikipedia.org/wiki/ANSI_escape_code#DOS,_OS/2,_and_Windows.

@ThePizzaMuncher
Copy link

Sorry, I know this is an old thread. To get control sequences working in the Windows console, you will want to SetConsoleMode(...) to enable ENABLE_VIRTUAL_TERMINAL_PROCESSING on the output handle. This is not the default for compatibility reasons (sorry!)

Sorry for necroing again, but I can’t get that to work when I include FMT. When I don’t include FMT, it functions, but if I do I get issues like identifier "STD_INPUT_HANDLE" is undefined (on HANDLE h0ut = GetStdHandle(STD_INPUT_HANDLE);), identifier "ENABLE_VIRTUAL_TERMINAL_PROCESSING" is undefined and too few arguments in function call (on SetConsoleMode(ENABLE_VIRTUAL_TERMINAL_PROCESSING))

@vitaut
Copy link
Contributor

vitaut commented Apr 1, 2022

STD_INPUT_HANDLE is not used in the current version of {fmt}.

@ThePizzaMuncher
Copy link

This was a combination of things randomly working and not working, and me being a complete oaf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants