-
-
Notifications
You must be signed in to change notification settings - Fork 780
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 hyperlink support to fd #1571
base: master
Are you sure you want to change the base?
Conversation
Fixes: sharkdp#1295 Fixes: sharkdp#1563
Thank you! Should we maybe make this an option instead of a flag, to avoid future breaking changes in case we see the need for e.g. |
Something wrong happens if a filename contains non-latin characters. |
The problem, is I based the code on the implementation in ripgrep. But while ripgrep is writing directly to the stream, I am using a Formatter, which means I have to write characters, not raw bytes. Thus we need to percent encode all non-ascii bytes (or we could switch to writing bytes directly, but that would be more complicated, and I think percent encoding is safer anyway).
@tmccombs This latest commit seems to fix the bug with non-latin chars, thanks :) |
The value can be auto, always, or never. | ||
|
||
Currently, the default is "never", and if the option is used without an argument "auto" is | ||
used. In the future this may be changed to "auto" and "always". |
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.
Although I love OSC8 as well (thank you for the PR ❤️ ), I'm not sure they're so mainstream that we should go in that direction :/
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.
My question is how do terminals that don't support it handle the sequence? If most terminals silently ignore unrecognized OSC sequences, then it probably doesn't hurt to emit it even if it isn't supported. We'll need to test that.
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.
weston-terminal at least simply ignores the OSC 8 sequence.
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.
FWIW, LGTM!
The print separator change is quite nice as well, I hope it won't make too noise for the PR to be unchecked though :/ (please add links!)
|
||
impl fmt::Display for PathUrl { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
write!(f, "file://{}", host())?; |
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.
Why do we need the hostname? Does file:///home/user/...
not work?
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.
It does. As long as fd is running on the same host as the terminal. Including the hostname is useful if you run the command over ssh or in a container or VM.
See https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda#file-uris-and-the-hostname
src/hyperlink.rs
Outdated
#[cfg(windows)] | ||
b'\\' => f.write_char('/'), | ||
_ => { | ||
write!(f, "%{:X}", byte) |
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.
RFC 3986 says that the byte 1
should become %01
not %1
. But to avoid having to know that, maybe we could just use https://crates.io/crates/urlencoding?
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.
Unfortanetely, I don't think that urlencoding
would work, because it would percent encode "/", which isn't what we want.
When the first digit is 0
Fixes: #1295
Fixes: #1563