Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

tmccombs
Copy link
Collaborator

@tmccombs tmccombs commented Jun 8, 2024

Fixes: #1295
Fixes: #1563

@sharkdp
Copy link
Owner

sharkdp commented Jun 9, 2024

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. --color=never --hyperlink=always or potentially other ways of printing hyperlinks?

@097115
Copy link

097115 commented Jun 9, 2024

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).
@097115
Copy link

097115 commented Jun 10, 2024

@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".
Copy link

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 :/

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link

@BuonOmo BuonOmo left a 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())?;
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants