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
v0.8.0 Fix wrapped filenames with hyperlinks #223
v0.8.0 Fix wrapped filenames with hyperlinks #223
Conversation
Hi @dandavison But I was thinking we shall preserve the links? I mean in case of wrapping where text is just a link with no other content, all lines would be links. |
Hi @zhiburt, good call! I agree. I didn't do that last night because I wanted to think about the API, but I'm going to have a go now. I'm thinking that the best way might be to return a prefix and a suffix, that can be reapplied to each fragment of text. |
I think you're correct with a fix. tabled/src/features/width/wrap.rs Line 354 in 34e2d93
Do you still working on this? |
Thanks! Yes, I'm working on this. I'm almost ready to open a PR. Hopefully I can do it this evening. Here's my current diff: |
Hi @zhiburt, OK, this is very close I think.
So that is almost correct. There's just a small bug with the way the colors are starting too early, at the ends of the lines: The bug only occurs with I'm guessing we should look for this bug in the previously existing code, but I might be wrong :) Anyway, what do you think? Shall we fix nushell tables with an update to tabled including this? And if you're able to help find that bug that would be awesome, but I'll look too. |
a39052e
to
eef2e51
Compare
loving this team work - excited to see a fix in nushell, although a light colored terminal is questionable. 🤣 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dandavison sorry for the delay.
I think the PR accomplish a general case.
Where we have a string being considered to be a link.
But it may not be always the case, see my comments bellow.
Yes that's why it's not that an easy issue, and doing it with no allocations is even more complex.
What do you think @dandavison am I right here?
@zhiburt thanks very much for reviewing carefully and catching those two points. I've updated the branch to strip the hyperlinks in the cases that you identified. I suggest that we leave it to future work to do the more sophisticated operations of reapplying parsed hyperlinks to the precise substrings that they should apply to. Meanwhile, nushell doesn't need that feature, and the current branch state will fix nushell. Does that sound OK to you? |
So you @dandavison return prefix/suffix only in case if 1 link is present and no additional text is there, otherwise you trim the links. Correct? let table = |text: &str| {
let data = [Distribution {
name: text.to_owned(),
is_hyperlink: true,
}];
Table::from_iter(data)
.with(
Segment::all()
.modify()
.with(Width::wrap(30).keep_words())
.with(Alignment::left()),
)
.to_string()
};
let text = format!(
"asd {} 2 links in a string {}",
format_osc8_hyperlink("https://www.debian.org/", "Debian"),
format_osc8_hyperlink("https://www.wikipedia.org/", "Debian"),
);
assert_eq!(
table(&text),
"+--------------------------------+--------------+\n\
| name | is_hyperlink |\n\
+--------------------------------+--------------+\n\
| asd Debian 2 links in a string | true |\n\
| Debian | |\n\
+--------------------------------+--------------+"
);
let text = format!(
"link: {}",
format_osc8_hyperlink("https://www.debian.org/", "Debian"),
);
assert_eq!(
table(&text),
"+--------------------------------+--------------+\n\
| name | is_hyperlink |\n\
+--------------------------------+--------------+\n\
| link: Debian | true |\n\
+--------------------------------+--------------+"
);
let text = format!(
"{} :link",
format_osc8_hyperlink("https://www.debian.org/", "Debian"),
);
assert_eq!(
table(&text),
"+--------------------------------+--------------+\n\
| name | is_hyperlink |\n\
+--------------------------------+--------------+\n\
| Debian :link | true |\n\
+--------------------------------+--------------+"
);
I think you may be right. Could you add tests? Let me know if you don't have time. |
Will do! |
Hi there, So what do you think shall we merge?
Personally I am OK with it, as it should not happen often.
As we've discussed already it may be left as a TODO, but if you wish welcome 😅
I could be intentional could you show the string you've used?
True but where it may become an issue? |
Hi @zhiburt, no problem!
You can see the issue in the output of
You can see it in the spaces between the word "Debian". (Even if you get rid of the hyperlink, there are still spaces inserted) |
Right:
Great! I'm working on removing all usage of |
OK, great. I don't think it's immediately necessary for nushell, since nushell links are a single color. So I think it would be OK to create an initial release fixing nushell that doesn't contain the fix in master. (But if you know how to apply the fix to this branch then please feel free to push commits to my branch) (By the way, I've now removed all usage of |
Thank you @fdncred I think this is an excellent point, and very relevant. It gives a great real-world test that everything is working correctly. On a first look, I sort of think there may be a bug: I think sometimes the way it is inserting the ANSI colors for the For example, try searching for a single letter like |
Ah, thanks. Looks like it's an Alacritty bug. Works on Wezterm. Do you see it on Alacritty? I can report it to Alacritty this evening. It's what I also mentioned above: #223 (comment) |
I'm not sure how to enable links in alacritty. A quick search didn't reveal much. I enabled url: and laucher: but it doesn't seem to repond to it. so i'm not really sure what is wrong. |
….8.0-vte-ansi-iterator-hyperlinks
I guess it's finished right? I hope I resolved the conflicts. I wonder if this is correct? Lines 2468 to 2483 in 42addd7
Also the question do you plan to publish |
Great. What do you think about just copying |
Sounds good, I'll work on it. But still is it correct? Lines 2468 to 2483 in 42addd7
|
Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
…avison/tabled into arthurdent-v0.8.0-vte-ansi-iterator-hyperlinks
It was correct, Thanks for your contribution once again. |
Nice work finishing this off @zhiburt! I'm running your branch nushell/nushell#6286 in my local nushell to test it. I'm a bit busy the next two weeks but later on I'll look into getting that crate published, and I'd like to help out with benchmarking / optimizations if I get time. |
Hi @dandavison Wanted to notice that; Some example of an usage. I also would like to highlight 1 behavior. Parsing this string |
Cool! My only request is: can we try to keep the VTE parser functions used in
Yes I'm open to suggestions here. I'm not sure of the details right now but I think that one reason I ignore
|
To be clear: my concrete hope here is that delta and nushell and tabled / ansitok can share a single implementation of the VTE |
Hi @zhiburt, this patch fixes nushell bug nushell/nushell#6553 causing filenames in narrow tables to be incorrectly displayed, and fixes #203. The patch was made against tabled v0.8.0 (the version of tabled that nushell is currently using), but as you can see it's a tiny change, which can also be made against
src/features/width/wrap.rs
in your devel branch of tabled (here's a branch targeting your current master). I thought this PR targeting v0.8.0 might be more useful for getting the fix into nushell sooner. The crate it's using is here. It has unit tests and has been well tested by users, running in delta for a couple of years now.I've added one example:
cargo run --example hyperlink_keep_words
displays a table which is incorrect without the patch:On this branch
With the patch reverted
Currently it's simply removing the hyperlinks. I have the code to re-apply the hyperlinks to the wrapped segments, but I didn't want to disturb your
split_keeping_words
andsplit
functions.