-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Zero width format #912
Zero width format #912
Conversation
I'm not so familiar with this corner of terminal IO. What is the normal syntax for zero-width markers in other similar languages? (bash/zsh?) |
zsh uses |
The motivation here is to let eliding be correct if NINJA_STATUS contains ansi codes, right? Maybe we could have the eliding function not count ansi codes when computing widths? |
I could for see using it to change tmux's title using its escape codes, but right now I'd be fine with color. Does the color stripping understand 256color sequences? |
Are they special? Currently it does this: https://github.com/martine/ninja/blob/master/src/util.cc#L477 |
Here's the command which does the work of setting the title for me: printf "\033]2;%s\033\\" "$title" |
I meant the 256color sequences. (Do I understand you correctly that you want your ninja status to modify your tmux title? Why?) |
Ah, sorry, missed the context. Well, I don't personally, but this would also support that seamlessly (possibly counting down the targets?). Here's my 256-color code: for color in {0..255}; do
ZSH_COLOR[$color]=$'\033[38;5;'$color'm'
ZSH_COLOR_PS1[$color]="%0{${ZSH_COLOR[$color]}%}"
done It looks like the existing code should work. |
@nico modifying your terminal title is commonly a hack for long-running processes to display status in a more visible place like alt-tab lists. Some WMs even let you "shade" a window (collapsing it to its title bar) as a substitute for minimization. |
Right, but is this something one would want to do every time a ninja command updates? (I honestly don't know.) If we end up doing #486 (which I currently do want to do, to get colors from clang diagnostics on Windows), ninja will have some knowledge about ansi codes anyhow, so it doesn't seem unreasonable for Elide() to learn about them too maybe. Are there other use cases for zero-width markers other than ansi codes? |
From a pedantic perspective it's hard to know in advance the full (PS: there was actually a vulnerability in one of these in the terminal However it might be the case that everything these days uses ANSI-style On Sat, Feb 28, 2015 at 1:35 PM, Nico Weber [email protected]
|
|
Fixed the |
afe0d24
to
371c16b
Compare
If the string fits, just use it. If we need the ellipses, *then* we need to compute the width based on that.
This is useful for color control sequences so that they do not cause unnecessary elision (or get elided themselves causing either color leakage or split control sequences).
371c16b
to
59fe29e
Compare
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.
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.
Some parts of this are still necessary. It looks like the width of escape sequences aren't removed when calculating elision. This can cause color leakage if the "clear color" sequence is elided. |
https://github.com/ninja-build/ninja/pull/1454/files#diff-005d118f141929270b3e1c4150887ae2R573 implements the stripping for Also #1210 might be the better solution, to keep Ninja simple. |
Working on a patch now. It does ANSI detection by "spans" so that there's only a single |
Also, the linked patch isn't right because it detects elision properly, but doesn't split the string using the escape sequence information to not slice in the middle of one. |
Yeah, getting this right can be tricky, as you also don't want to skip any escape sequences even when they are in the elided area. I've already implemented it in Python here: https://github.com/jhasse/ja/blob/6603076e84083ed9155404268336b5ce5a771bc4/ja/native.py#L244 |
Almost have it. PR up shortly. |
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.
I decided to not do
%0{
and%}
because the logic for control sequences more than just a single character is a messier. I can also change it over to%{
and%}
if separate open/close sequences are preferable. It is not (currently) an error to have mismatched open/close sequences, but it is also not a zero-width section and%0
will be literal in that case.Fixes #713.