hyperlink
only.Expand description
Experimental support for hyperlinking.
§Usage
Enable the hyperlink
crate feature. Enabling hyperlink
implicitly
enables std
.
Import the HyperlinkExt
extension trait and use the link()
builder
method.
use yansi::Paint;
use yansi::hyperlink::HyperlinkExt;
println!("Go to {}.", "our docs".link("https://docs.rs/yansi").green());
>
Go to our docs.
The link()
method returns a PaintedLink
structure which implements all
of the unverisal chainable methods available across the library.
Furthermore, Painted
is extended with a link()
method. The net effect is that you can use link()
as if it were any other
styling method:
use yansi::Paint;
use yansi::hyperlink::HyperlinkExt;
println!("Go to {}.", "our docs".green().link("https://docs.rs/yansi").on_black().invert());
>
Go to
our docs
.
§Caveats
-
You can only create a link when there is a target value to print, that is, when the receiver is something “printable”. In other words, you cannot apply
link()
to a bareStyle
. This means the following will not work:ⓘuse yansi::{Paint, Style, Color::*}; use yansi::hyperlink::HyperlinkExt; static LINKED: Style = Green.link("https://docs.rs/yansi");
-
While some modern terminals support hyperlinking, many do not. Those that do not should gracefully ignore the target URL and print the original value. That is, instead of
>
our docs, such terminals would print>
our docs.
Structs§
- A
Painted
with an associated target URL to hyperlink.
Traits§
- Extension trait to apply hyperlinks to any value, implemented for all types.