-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
add a string width
subcommand
#4012
Comments
So, for the easily confused (i.e. me), could you explain why this shouldn't be changed in or added to E.g. |
@faho: The reason is that This is basically a steaming pile of ugliness due to legacy issues. Note that Python 3.6 reports a length of 2 for your We could add one or more flags to The primary purpose of this proposal is to make it easy to find out the length of individual code points. So that we don't have to manually hack a version of fish that reports that information when debugging problems like #3989 and #4011. The secondary purpose is to potentially make it possible to calculate the visual width of a string that contains combining unicode chars and ANSI X3.64 sequences for more sophisticated prompts. |
This looks like a good idea. And I agree that it should be a separate command and that |
I've also been looking for a way to count the visible characters in a string, when I was directed to this thread. |
So... I've been working on this a bit, and I'm not actually sure it's a good idea. The major problem is that it doesn't solve most problems you'd want it to, or it'd have some really weird edge-cases. E.g. @terrycloth: Your problem was figuring out the width of the output of Any version that parses escapes is asking for trouble, but any version that doesn't would barely help you - it'll help you if you've picked e.g. an emoji as a git status character, by counting it as 2 instead of 4 like Then there's control characters in general. We can't use fish_wcswidth, as that returns -1 for any string that includes any nonprintable. Should we count nonprintables as 0? What about backspace? That's actually -1. What about \r? The logic here is surprisingly hard to get right. |
I've also been working on this. It's not as simple as just doing wcwidth, we also need to ignore the escapes that we do elsewhere in the code. |
Also that "strip-ansi-cli" thing mentioned on the mailing list boils down to const pattern = [
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
].join('|'); after you go two dependencies deep. That's javascript for you. |
I was thinking to actually take advantage of pcre2 here. |
I mean... you can use a regex to match. The problem is which regex. And does your terminal actually agree with your interpretation? |
I'd be happy with it just correctly showing the width of emoji (though being able to get the visual width would be awesome, too). My host name is ⭐🔥 (For anyone that doesn't show up for, it's the emoji for Star and Fire). Like my (Giving credit where it's due: the ASCII art isn't mine, it's by Jeff Ferris, found here.) |
Fixed with #8182. |
When issues like #3989 and #4011 are opened I frequently find myself hacking a fish binary to tell me what
fish_wcswidth()
returns for the non-ASCII characters. There really should be a standard mechanism for getting that information. It seems like astring width
subcommand is what is needed. By default it reports the cumulative width of each string one per line. With the-i
/--individual
flag it would report the width of each individual character in each string. With the-v
/--verbose
flag it would print a symbolic representation of each char and its width.This would allow you to type
string width \u009C
to learn that fish thinks that char has width -1 (i.e., the width is undefined).The first implementation would not support ANSI X3.64 escape sequences. So it couldn't be used to determine the "visual" width of something like the output of
fish_prompt
. That's an enhancement we might add in the future.The text was updated successfully, but these errors were encountered: