Skip to content

Add a Link type for printing OSC 8 hyperlinks - #295

Open
ChrisJr404 wants to merge 1 commit into
console-rs:mainfrom
ChrisJr404:add-hyperlink
Open

Add a Link type for printing OSC 8 hyperlinks#295
ChrisJr404 wants to merge 1 commit into
console-rs:mainfrom
ChrisJr404:add-hyperlink

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #132.

console already recognizes OSC 8 hyperlinks when stripping/measuring text, but there was no way to emit one. This adds a small Link wrapper, in the same spirit as Emoji, that prints text as an OSC 8 hyperlink on terminals that support it.

Like styling, the escape is only written when colors are enabled for the target stream, so piped or redirected output just shows the plain text. You can force it on or off with .force(..) and target stderr with .for_stderr().

use console::Link;
println!("Read the {}.", Link::new("docs", "https://docs.rs/console"));

I went with Link::new(text, url) so it reads a bit like a Markdown link, but I'm happy to flip the order if you'd rather have the url first. epage linked anstyle-hyperlink on the issue as a reference; I kept this minimal for now and left out the optional id= parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print hyperlinks

1 participant