Skip to content

Commit

Permalink
feat(env): Provide direct access to env introspection (#6)
Browse files Browse the repository at this point in the history
Looking to use this library where we do our own TTY detection and would
like that decoupled from the env inspection, much like
`supports-hyperlinks`.
  • Loading branch information
epage committed Jan 9, 2024
1 parent 59d3473 commit 88f56c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ fn is_a_tty(stream: Stream) -> bool {
}
}

/// Returns true if `stream` is a TTY or the current terminal
/// [supports_unicode].
pub fn on(stream: Stream) -> bool {
if !is_a_tty(stream) {
// If we're just piping out, it's fine to spit out unicode! :)
true
} else if std::env::consts::OS == "windows" {
} else {
supports_unicode()
}
}

/// Returns true if the current terminal, detected through various environment
/// variables, is known to support unicode rendering.
pub fn supports_unicode() -> bool {
if std::env::consts::OS == "windows" {
// Just a handful of things!
std::env::var("CI").is_ok()
|| std::env::var("WT_SESSION").is_ok() // Windows Terminal
Expand Down

0 comments on commit 88f56c7

Please sign in to comment.