You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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 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.
Activity
evmar commentedon 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 commentedon Jan 28, 2014
On Tue, Jan 28, 2014 at 08:54:00 -0800, Evan Martin wrote:
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 commentedon Jan 30, 2014
It looks like bash uses '[' and ']' to delimit zero-width portions. Do you have a preference? Maybe something else?
mqudsi commentedon 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 inJOB_STATUSbut 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.
Support ANSI escape color codes in NINJA_STATUS
Support ANSI escape color codes in NINJA_STATUS
jhasse commentedon Nov 7, 2018
Yes, that sounds like the best idea. Ideally that counting should only be done once (when parsing
NINJA_STATUS) and not inElideMiddle.It's supported:
env $'NINJA_STATUS=\x1b[32m[%f/%t] \x1b[0m' ninjaThe problem is
EllideMiddle.mathstuf commentedon 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
descriptionnever contains ANSI escape sequences. If it does support that, you need to figure outConsoleWidthevery call.util: handle elision around ANSI escape sequences
util: handle elision around ANSI escape sequences
Support ANSI escape color codes in NINJA_STATUS
torarnv commentedon Apr 25, 2024
I was happy to see that
NINJA_STATUSsupports 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 commentedon Apr 25, 2024
See #1584.
torarnv commentedon 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 commentedon Apr 25, 2024
Sorry, I meant #1494.
Correctly handle ANSI Escape Codes in ElideMiddle, fix ninja-build#713
Correctly handle ANSI Escape Codes in ElideMiddle, fix ninja-build#713
Correctly handle ANSI Escape Codes in ElideMiddle, fix ninja-build#713
Merge pull request #2428 from jhasse/elide-middle-ansi-escape
Correctly handle ANSI Escape Codes in ElideMiddle, fix ninja-build#713
Correctly handle ANSI Escape Codes in ElideMiddle, fix ninja-build#713
Merge pull request ninja-build#2428 from jhasse/elide-middle-ansi-escape