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 color in NINJA_STATUS #713

Closed
mathstuf opened this issue Jan 28, 2014 · 10 comments
Closed

Support color in NINJA_STATUS #713

mathstuf opened this issue Jan 28, 2014 · 10 comments

Comments

@mathstuf
Copy link
Contributor

It would be nice if ninja understood color natively. Currently, I have a wrapper script which tests stdout for being a terminal and changes NINJA_STATUS accordingly. The problem is that ninja doesn't know that the color escape sequences are really zero-width when printed on the terminal and causes elision to happen at improper places.

@evmar
Copy link
Collaborator

evmar commented Jan 28, 2014

I think bash handles this by special markers that delimit regions that have
no width. Would that work for you?

brevity due to phone

@mathstuf
Copy link
Contributor Author

On Tue, Jan 28, 2014 at 08:54:00 -0800, Evan Martin wrote:

I think bash handles this by special markers that delimit regions that have
no width. Would that work for you?

Looking at zsh, it uses %0{$zero_width%} to denote such sections. I
don't see anything in the bash man page, but I'd be fine with that as
well.

@mathstuf
Copy link
Contributor Author

It looks like bash uses '[' and ']' to delimit zero-width portions. Do you have a preference? Maybe something else?

@mqudsi
Copy link
Contributor

mqudsi commented Jul 30, 2018

Why not just hard-code an ignore for ansi escape codes (or at least ansi escape color codes) when counting the characters as #912 is trying to do?

This seems to be going about it the hard way, adding complexity both to the code and to the language. Current situation: no ansi codes are supported in JOB_STATUS. If we go with a hard-coded patch for ansi color codes, the situation becomes no ansi codes aside from ansi color codes are supported in JOB_STATUS but with zero additional cost or complexity (aside from a change to the status length counter function).

This could have been a twenty minute patch, but now it's turned into a five-year ordeal due to difficult decisions finding the perfect syntax.

mqudsi added a commit to mqudsi/ninja that referenced this issue Jul 30, 2018
Adds support for ANSI escape sequences used for colorization to the job
status indicator, and updates `ElideMiddle()` to account for the
non-obvious change in text width.

As an example, the following will now emit the job status in green:

   env NINJA_STATUS="\\033[32m[%f/%t] \\033[0m" ninja;

Invalid color escape codes are treated as plain text (as before). ANSI
escape sequences apart from `\033...m` are not supported.

Closes ninja-build#713. Closes ninja-build#912.
mqudsi added a commit to mqudsi/ninja that referenced this issue Jul 30, 2018
Adds support for ANSI escape sequences used for colorization to the job
status indicator, and updates `ElideMiddle()` to account for the
non-obvious change in text width.

As an example, the following will now emit the job status in green:

   env NINJA_STATUS="\\033[32m[%f/%t] \\033[0m" ninja;

Invalid color escape codes are treated as plain text (as before). ANSI
escape sequences apart from `\033...m` are not supported.

Closes ninja-build#713. Closes ninja-build#912.
@jhasse
Copy link
Collaborator

jhasse commented Nov 7, 2018

Why not just hard-code an ignore for ansi escape codes (or at least ansi escape color codes) when counting the characters as #912 is trying to do?

Yes, that sounds like the best idea. Ideally that counting should only be done once (when parsing NINJA_STATUS) and not in ElideMiddle.

Current situation: no ansi codes are supported in JOB_STATUS.

It's supported:

env $'NINJA_STATUS=\x1b[32m[%f/%t] \x1b[0m' ninja

The problem is EllideMiddle.

@jhasse jhasse added the feature label Nov 7, 2018
@mathstuf
Copy link
Contributor Author

mathstuf commented Nov 7, 2018

To do the count once, a map of console width to string length would be necessary. But it is possible to elide it as long as the description never contains ANSI escape sequences. If it does support that, you need to figure out ConsoleWidth every call.

mathstuf added a commit to mathstuf/ninja that referenced this issue Nov 14, 2018
mathstuf added a commit to mathstuf/ninja that referenced this issue Nov 14, 2018
mqudsi added a commit to mqudsi/ninja that referenced this issue Jan 1, 2019
Adds support for ANSI escape sequences used for colorization to the job
status indicator, and updates `ElideMiddle()` to account for the
non-obvious change in text width.

As an example, the following will now emit the job status in green:

   env NINJA_STATUS="\\033[32m[%f/%t] \\033[0m" ninja;

Invalid color escape codes are treated as plain text (as before). ANSI
escape sequences apart from `\033...m` are not supported.

Closes ninja-build#713. Closes ninja-build#912.
@jhasse jhasse added this to the 1.13.0 milestone Apr 11, 2024
@torarnv
Copy link

torarnv commented Apr 25, 2024

I was happy to see that NINJA_STATUS supports ANSI color codes, but surprised to see that adding those made the actual build message elided/truncated earlier than the width of the terminal. +1 on fixing this by just ignoring ANSI escape sequences when computing the eliding.

@mathstuf
Copy link
Contributor Author

See #1584.

@torarnv
Copy link

torarnv commented Apr 25, 2024

@mathstuf As far as I can tell #1584 is about stripping color codes for non-color capable terminals/output. The problem reported above is that ninja's eliding logic doesn't take escape codes into account. It should, when deciding how to elide the output, regardless of the output terminal's capabilities.

@mathstuf
Copy link
Contributor Author

Sorry, I meant #1494.

@jhasse jhasse closed this as completed in 7454b0b May 14, 2024
jhasse added a commit that referenced this issue May 14, 2024
Correctly handle ANSI Escape Codes in ElideMiddle, fix #713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants