-
-
Notifications
You must be signed in to change notification settings - Fork 47
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 support for hyperlinks #65
Conversation
I added a simple I tried to add something like this, in order to support multi-colored links and get rid of writer.write_hyperlink(|w| {
w.set_color(...)?;
w.write_all(directory)?;
w.set_color(...)?;
w.write_all(file)
}); But due to wrappers such as |
This ensures the termcolor version from my other PR is available. BurntSushi/termcolor#65
Is any of this necessary to get hyperlink support working in ripgrep? Basically, would it make sense to land this without doing this work? (I'm finally digging into this hyperlink issue and trying to make sense of everything. :-)) |
I don't think hyperlink parameters are necessary at all TBH. The hyperlink spec defines them, but AFAIK they aren't used anywhere. It only states: "These parameters allow future extendability of this feature." BTW, I ended up not using Oh, I also merged master into my branch, sorry. 😅 I squashed everything into a single commit. |
eeefc5f
to
ba49fa8
Compare
Yeah squashing everything down into one commit would be great. And definitely remove anything that isn't necessary. :-) |
ba49fa8
to
ff2ae2b
Compare
Done 🙂 |
Thank you! |
So looking at this more closely, it seems like the The other thing I'm confused about is why the hyperlink is just a link and doesn't have a label. How does the label get set? I'd expect that to be an ANSI escape code too? I haven't quite done the full background reading yet... |
Oh... I see. Wow. The example in this doc helped explain things. So basically, after So |
The other thing that is rather annoying here is that this apparently does not work at all in tmux. I saw your issue here, and it's closed. I built revision |
OK, figured out the tmux issue: https://github.com/BurntSushi/dotfiles/blob/4f29beb508708e8a88676ffa194f0dc9c19057ae/.tmux.conf#L17-L20 Thanks to this: tmux/tmux#3660 |
I've changed the docs on
I was very confused about how to use this API until I actually started reading about OSC8 and actually trying an example. I tried to re-word the docs to target my confusion as I suspect others will be confused. Notice also that I rename |
I also removed the |
And the new trait method |
And of course, adding |
This commit adds a new type `HyperlinkSpec` and two new default methods to the `WriteColor` trait: `set_hyperlink` and `supports_hyperlinks`. The former is the analog to `set_color`, but for hyperlinks. The latter is the analog to `supports_color`. By default, the former is a no-op and the latter always returns `false`. But all ANSI-supported impls of `WriteColor` in this trait now support it in accordance with OSC8[1]. Closes #65 [1]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
You figured it out, but FYI Apparently removing it made the API more confusing. 😕
I had to run tmux with
I agree it's better that way. 👍
I wasn't sure about that one, I thought it was idiomatic to add After you renamed
I should have thought about introducing a default implementation. 👍 Thanks for handling this! 🙂 |
I'd like to implement hyperlink support in ripgrep (BurntSushi/ripgrep#665), and this is the first step, as per your comment @BurntSushi.
I had to make some design choices here, which I can adjust after getting your input:
Currently,
reset
does not reset the hyperlink, only the color. That's not necessarily the best choice, and I'm not sure what to do here, so I need your guidance. My reasoning was:set_reset
) would get in the way, and callingset_color
could reset the hyperlink, which would be unexpected. I could only reset the color in that case though. On the other hand,reset
not resetting everything is also unexpected. 😕"\x1B[0m\x1B]8;;\x1B\\"
instead of"\x1B[0m"
), not sure if that's an issue. Maybe that could be mitigated by adding some state inAnsi
, so it would only emit the hyperlink reset code if previously emitted a hyperlink?An alternate implementation would be a
write_hyperlink
function which takes the URI and text to write in a single call, but that would prevent from using multiple colors in a hyperlink easily. I suppose another function which takes a closure would need to be provided in order to handle this case.I didn't add support for link parameters yet. These can be added later to the
HyperlinkSpec
type:id
is defined)So, please tell me which solution you prefer and I'll implement it. 🙂
I tested this with Windows Terminal.