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
Welcome to fish, the friendly interactive shell
Type helpfor instructions on how to use fish
ilan@arch ~> string pad --width 20 hello
hello
ilan@arch ~> string pad --width 20 \ehello
ello
ilan@arch ~> string pad --width 20 (set_color red)hello
hello
ilan@arch ~>
It would be really nice if set_color and string pad would work together.
Honestly, now that I think about it, it wouldn't be so insane to design a shell and a terminal together. Yah people couldn't use whatever their favorite terminal was or whatever, but you could probably do some pretty great stuff with that integration. Off topic though 😂
$ string pad --width 20 (set_color red)hello hello
hello
hello
The escape sequences take 6 characters.
We'll have to think about whether it makes sense to support colors here. Maybe there should be a different command to remove escapes?
Fun fact: This needs to handle multline strings, and there are some ambiguities.
If you have a string like
echo aaa\nbb
The width of that is 3 and then 2. Calling it "3" (the maximum) doesn't make sense, calling it 6 (the "length) makes even less. Really 3, 2 is the correct answer.
But if you have one like
echo aaa\rbb
The width of that is? "3" sorta makes sense because that is how wide it would show up in isolation (it would look like "bba"), but "2" would also make sense because, if you add anything to it it works like it's 2 cells wide (printing a "1" would make it look like "bb1", not "bba1").
And if the "aaa" wraps into the next line? All bets are off. We can't detect it, we can't express it.
I would probably call this "2" wide because that's what it is as soon as anything else happens. It's also easier to handle - as soon as you encounter a \r, reset the width of the current line to 0. (And if you encounter a \n, the line is done)
I would probably call this "2" wide because that's what it is as soon as anything else happens. It's also easier to handle - as soon as you encounter a \r, reset the width of the current line to 0. (And if you encounter a \n, the line is done)
For posterity: string length -V aaa\rbb aa\rbbb prints "3" two times. It keeps the longest width. This is to make wrapping calculations work. It also makes \r\n not a problem.
Activity
faho commentedon Mar 6, 2021
In general, this is to be expected, interpreting arbitrary escape sequences here would require us to become a terminal.
We could probably handle colors and such.
IlanCosman commentedon Mar 6, 2021
Honestly, now that I think about it, it wouldn't be so insane to design a shell and a terminal together. Yah people couldn't use whatever their favorite terminal was or whatever, but you could probably do some pretty great stuff with that integration. Off topic though 😂
IlanCosman commentedon Mar 23, 2021
Huh, this seems to work now with Fish 3.2.1 on MacOS and Fish master on Arch. I guess something in 3.2.1 fixed it. 👍
krobelus commentedon Mar 23, 2021
I don't think it's fixed, see this:
The escape sequences take 6 characters.
We'll have to think about whether it makes sense to support colors here. Maybe there should be a different command to remove escapes?
IlanCosman commentedon Mar 23, 2021
Good point, it's not fixed.
👀 yes please! I've been rolling my own.
faho commentedon Jul 17, 2021
Fun fact: This needs to handle multline strings, and there are some ambiguities.
If you have a string like
The width of that is 3 and then 2. Calling it "3" (the maximum) doesn't make sense, calling it 6 (the "length) makes even less. Really 3, 2 is the correct answer.
But if you have one like
The width of that is? "3" sorta makes sense because that is how wide it would show up in isolation (it would look like "bba"), but "2" would also make sense because, if you add anything to it it works like it's 2 cells wide (printing a "1" would make it look like "bb1", not "bba1").
And if the "aaa" wraps into the next line? All bets are off. We can't detect it, we can't express it.
I would probably call this "2" wide because that's what it is as soon as anything else happens. It's also easier to handle - as soon as you encounter a
\r, reset the width of the current line to 0. (And if you encounter a\n, the line is done)faho commentedon Mar 24, 2022
For posterity:
string length -V aaa\rbb aa\rbbbprints "3" two times. It keeps the longest width. This is to make wrapping calculations work. It also makes\r\nnot a problem.