Feature proposal: Links in crate names

Proposal

Cargo outputs crate names when building, updating, downloading, etc. It would be handy to have the names link to the relevant crates.io page using OSC 8 links. Cargo already uses OSC 8 links for HTML file output as of #12889, so some of the machinery is already in place.

Motivation

Changelogs

When I run cargo update, I get a list of updated crates:

$ cargo update
     Locking 4 packages to latest Rust 1.98.0-beta.6 compatible versions
    Updating clap v4.6.5 -> v4.6.6
    Updating clap_builder v4.6.5 -> v4.6.6
    Updating zerocopy v0.8.55 -> v0.8.56
    Updating zerocopy-derive v0.8.55 -> v0.8.56

If I want to see what's changed in these crates, I can either run (e.g.) cargo info clap to get a link to the crate's home page or repository and find the changelog from there, or I can go to https://crates.io/crates/clap to find the changelog. It would be handy to be able to click on clap in the cargo update output to go straight to crates.io.

Unknown crates

Adding a crate might pull dependencies on other crates I'm not familiar with (placeholder names):

$ cargo add foo
    Updating crates.io index
      Adding foo v1.2.3 to dependencies
    Updating crates.io index
     Locking 5 packages to latest Rust 1.98.0-beta.6 compatible versions
      Adding foo v1.2.3
      Adding bar v4.5.6

If I want to learn what bar does, I again need to either run cargo info bar or go to https://crates.io/crates/bar. Links would save time.

Unsupported Terminals

In terminals that don't support OSC 8, Cargo could continue following the current behaviour and output plaintext crate names.

6 Likes

I would love for us to leverage links more. I know some users have complained about click-to-focus activating links but likely in those cases, they should disable the links.

There is the question of what link to provide

  • package.homepage with a fallback to crates.io if it came from there
  • package.documentation with a fallback to docs.rs if it came from crates.io
  • crates.io if it came from there
2 Likes

Linking to crates.io is safest. Custom URLs can be broken (novelty .rs domains expire), or incorrect (people forking crates often forget to update the links).

To add more value than copy pasting just the crate name, you could link to version-specific crates.io URL.

7 Likes

Or, perhaps, fix their window manager :wink: .