Skip to content

Commit

Permalink
feat(force): add support for forcing hyperlinks
Browse files Browse the repository at this point in the history
Fixes: #2
  • Loading branch information
zkat committed Sep 16, 2021
1 parent 876ba1e commit 96d75a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ if supports_hyperlinks::on(Stream::Stdout) {
```

And that's it!

## Forcing hyperlinks in tools that use `supports-hyperlinks`

You may set the `FORCE_HYPERLINK` environment variable to force
`supports-hyperlinks` to return true for its checks. If the value is `0`, this
will force it to be _false_, instead.
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ pub use atty::Stream;
/// Returns true if the current terminal, detected through various environment
/// variables, is known to support hyperlink rendering.
pub fn supports_hyperlinks() -> bool {
// Hyperlinks can be forced through this env var.
if let Ok(arg) = std::env::var("FORCE_HYPERLINK") {
return arg.trim() != "0";
}

if std::env::var("DOMTERM").is_ok() {
// DomTerm
return true;
Expand Down Expand Up @@ -40,5 +45,5 @@ pub fn supports_hyperlinks() -> bool {
/// Returns true if `stream` is a TTY, and the current terminal
/// [supports_hyperlinks].
pub fn on(stream: Stream) -> bool {
atty::is(stream) && supports_hyperlinks()
(std::env::var("FORCE_HYPERLINK").is_ok() || atty::is(stream)) && supports_hyperlinks()
}

0 comments on commit 96d75a7

Please sign in to comment.