From 0e7938d03341bd10c32442fa982dde8763314aed Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 8 Jan 2024 12:32:19 -0600 Subject: [PATCH] feat: Provide direct access to env introspection 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`. --- src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b47b39b..2093186 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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