-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Turn HTML output into links #12888
Comments
Things we'd need to work through: In theory, terminals that support ANSI escape codes should either support or gracefully degrade in the presence of hyperlinks and so we could do this based on
impl Shell {
fn hyperlink(&self, link: &str) -> Hyperlink {...}
}
struct Hyperlink { ... }
impl Hyperlink {
fn open(&self) -> impl Display;
fn close(&self) -> impl Display;
}
format!("Some text with a {}{}{}", link.open(), path.display(), link.close()); Another tricky aspect, from the ripgrep discussion, is that you shouldn't leave the hostname as default for hyperlinks due to SSH ... except on Windows due to bugs. |
Also, iiuc ripgrep went above and beyond and supports hyperlink patterns for opening files in editors to a specific file/line which requires knowing what editor is being used. This is done with a specific flag. That means just for our use cases, we can skip that. If we want to extend this to cargo and rustc diagnostic messages, then we'd need to reconsider this. |
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
@Muscraft this could have interesting ramifications for diagnostics. At the most basic level, we could make links out of references to the manifest (like EDIT: Also, if we rewrote rustc's messages, then we could link to |
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
This provides an alternative to `--open`, where supported. Fixes rust-lang#12888
feat: Make browser links out of HTML file paths This provides an alternative to `--open`, where supported. Note: because we are relying on `supports-hyperlinks`, we are getting `FORCE_HYPERLINK` for "free". Unsure whether it and the current policy (it gets overridden by `term.hyperlinks`) is something we want. `FORCE_HYPERLINK` mirrors the npm package's behavior of the same name (see zkat/supports-hyperlinks#2) though though I also found reading of it in ohmyzsh, a go terminal library and many more places. Similarly, #12751 added indirect, undocumented support for community environment variables. Fixes #12888
Problem
In most terminals, if a URL is printed it is turned into a link you can click on for easy opening. This is less true for file paths.
This is less of a problem for
cargo doc --open
as cargo will open the page up for you.Places where we are falling short include
cargo doc --target foo --target bar
(--open
doesn't work)cargo doc
invocation that you can run multiple times, using shell history, without editing in/out--open
cargo doc
calls wrapped in other tools, likemake
cargo build --timings
(it'd be awkward to add a--open
just for--timings
)Proposed Solution
Turn the file paths into links using ANSI escape codes
Notes
From #12859 (review)
The text was updated successfully, but these errors were encountered: