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

Colours don't work in command prompt on Windows #56

Closed
woubuc opened this issue Jun 7, 2019 · 3 comments
Closed

Colours don't work in command prompt on Windows #56

woubuc opened this issue Jun 7, 2019 · 3 comments

Comments

@woubuc
Copy link

woubuc commented Jun 7, 2019

The colours are displayed as code in the standard command prompt on Windows 10.

What it looks like:
image

What it should look like (using Cmder):
image

Code used

I know the cmd supports colours, since Cargo displays colours just fine.

@noxabellus
Copy link

Running my exe with this crate, in the integrated powershell terminal in vs code on windows, if I run via cargo run, the coloring works, however if I run the executable directly it does not

@noxabellus
Copy link

For what its worth, I added this to the top of my main and it works now:

#[cfg(windows)] unsafe {
  let handle = winapi::um::processenv::GetStdHandle(winapi::um::winbase::STD_OUTPUT_HANDLE);
  let mut original_mode: winapi::shared::minwindef::DWORD = 0;
  winapi::um::consoleapi::GetConsoleMode(handle, &mut original_mode);
  winapi::um::consoleapi::SetConsoleMode(handle, winapi::um::wincon::ENABLE_VIRTUAL_TERMINAL_PROCESSING | original_mode);
}

@kurtlawrence
Copy link
Collaborator

kurtlawrence commented Jun 16, 2019

Hi @noxabellus and @woubuc, there is already a function to do that: set_virtual_terminal

It doesn't show up in the docs unless you set the platform to windows

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

No branches or pull requests

3 participants