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

Support ANSI colors on Windows #1451

Closed
Boddlnagg opened this issue Jul 16, 2018 · 10 comments
Closed

Support ANSI colors on Windows #1451

Boddlnagg opened this issue Jul 16, 2018 · 10 comments
Labels
Milestone

Comments

@Boddlnagg
Copy link

Clang's cl.exe has an option -fansi-escape-codes which makes it output ANSI colors instead of using the usual Windows console API. The console of Windows 10 in one of the updates gained the ability to show those colors correctly. This means that theoretically I could set that option and make Ninja correctly forward the colors (which can never work with the usual colors in Windows, because they are not part of the output stream).

However, it doesn't work for some reason, which I was not yet able to find out. Ninja will forward the colors with pool = console, but otherwise it won't. Furthermore, the the mode for automatic parsing of include dependencies via deps = msvc will probably also need to learn to ignore, but forward the ANSI escape codes.

@Befzz
Copy link

Befzz commented Jul 17, 2018

Windows user too(10 + clang), cmd.
can't get colored output without pool = console

coloredout
coloredout2
👆

@mqudsi
Copy link
Contributor

mqudsi commented Jul 31, 2018

@Befzz what build of Windows 10?

@Boddlnagg
Copy link
Author

Boddlnagg commented Aug 11, 2018

@Befzz What happens if you run clang-cl with -fansi-escape-codes directly, without going through Ninja?

Because now that I look at this again, I'm having the following problem (both on Windows 10 1709 and 1803): Clang with -fansi-escape-codes does not work correctly even without Ninja (looks like in the second screenshot above).

I think that I had some situation where it did work, and it that situation it still didn't work with Ninja which is why I opened this issue report. However, I don't remember what I did, and can't get it to work again. So this is primarily a problem in Clang or Windows. We should look at this issue again when it works correctly without Ninja (or could someone get it to work already?).

@evmar
Copy link
Collaborator

evmar commented Aug 11, 2018

We write to the console with a special Windows function that might evade however Windows 10 understands color, but looking at this code it looks like maybe in some cases with the console pool it falls back on fwrite, which might explain how you had it work at some point.
https://github.com/ninja-build/ninja/blob/master/src/line_printer.cc

@Boddlnagg
Copy link
Author

@evmar: I never had it working with Ninja, only without Ninja. But now I can't even get it to work without Ninja ...

@jhasse
Copy link
Collaborator

jhasse commented Oct 29, 2018

The console of Windows 10 in one of the updates gained the ability to show those colors correctly.

Unfortunately it only does so, after a WinAPI call, see #1462.

@Kazark
Copy link

Kazark commented Nov 14, 2018

It would be definitely be nice to see this. We mostly use ConEmu, which supports ANSI sequences, and we do have commands that emit colors. Some of them probably are not using ANSI sequences though...

@Boddlnagg
Copy link
Author

I'm not sure, but with the new ConPTY it might even be possible to capture classic (non-ANSI) colored console output on Windows. But ninja currently does not use pseudo ttys at all (see also the first entry in the FAQ).

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Feb 17, 2019
We've finally tagged a new release of Ninja, version v1.9.0!

The biggest feature of this release would be high-resolution
timestamps, so timestamps with a resolution under 1 second.
ninja-build/ninja#371

There are also several small quality-of-life improvements, for
example ninja now enables Windows 10's ANSI color escape code
support.  ninja-build/ninja#1451

For a complete list of changes see:
ninja-build/ninja@v1.8.2...v1.9.0
@Salamandar
Copy link

Hi, this still does not work on Mingw/Msys2. Gcc correctly outputs colors when called manually with the same args (-fdiagnostics-color=always), but not through Ninja.
Gcc correctly outputs colors when piped to less.

I tried ninja with a custom target calling a bash script :

# test_color.sh
#/bin/bash

echo -e "\033[34mbleu, \033[1mgras, \033[4msouligné, \
> \033[5mclignotant \033[7met surligné\033[0m"


# Meson target: 
custom_target('test_color',
  command: [
    find_program('bash'),
    join_paths(meson.current_source_dir(), 'test_color.sh'),
  ],
  output: 'test_color.sh',
)
  • The standalone script outputs colors
  • ninja test_color.sh does not outupt colors
  • If I add console: true, to the Meson code, the script is called with the console pool and colors appear.

@jhasse
Copy link
Collaborator

jhasse commented Mar 21, 2019

Are you running ninja through mintty (MSYS2's shell)? IIRC we only detect native Windows command prompts and therefore think that we're piped in that case. That's why ANSI escape codes get stripped.

Try running with CLICOLOR_FORCE=1 ninja or winpty ninja.

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

7 participants