summaryrefslogtreecommitdiffstats
path: root/vendor/supports-hyperlinks/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/supports-hyperlinks/src/lib.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/supports-hyperlinks/src/lib.rs')
-rw-r--r--vendor/supports-hyperlinks/src/lib.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/supports-hyperlinks/src/lib.rs b/vendor/supports-hyperlinks/src/lib.rs
new file mode 100644
index 000000000..83290b211
--- /dev/null
+++ b/vendor/supports-hyperlinks/src/lib.rs
@@ -0,0 +1,67 @@
+#![doc = include_str!("../README.md")]
+
+/// possible stream sources
+#[derive(Clone, Copy, Debug)]
+pub enum Stream {
+ Stdout,
+ Stderr,
+}
+
+/// 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;
+ }
+
+ if let Ok(version) = std::env::var("VTE_VERSION") {
+ // VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
+ if version.parse().unwrap_or(0) >= 5000 {
+ return true;
+ }
+ }
+
+ if let Ok(program) = std::env::var("TERM_PROGRAM") {
+ if matches!(
+ &program[..],
+ "Hyper" | "iTerm.app" | "terminology" | "WezTerm" | "vscode"
+ ) {
+ return true;
+ }
+ }
+
+ if let Ok(term) = std::env::var("TERM") {
+ if matches!(&term[..], "xterm-kitty" | "alacritty" | "alacritty-direct") {
+ return true;
+ }
+ }
+
+ if let Ok(term) = std::env::var("COLORTERM") {
+ if matches!(&term[..], "xfce4-terminal") {
+ return true;
+ }
+ }
+
+ // Windows Terminal and Konsole
+ std::env::var("WT_SESSION").is_ok() || std::env::var("KONSOLE_VERSION").is_ok()
+}
+
+fn is_a_tty(stream: Stream) -> bool {
+ use is_terminal::*;
+ match stream {
+ Stream::Stdout => std::io::stdout().is_terminal(),
+ Stream::Stderr => std::io::stderr().is_terminal(),
+ }
+}
+
+/// Returns true if `stream` is a TTY, and the current terminal
+/// [supports_hyperlinks].
+pub fn on(stream: Stream) -> bool {
+ (std::env::var("FORCE_HYPERLINK").is_ok() || is_a_tty(stream)) && supports_hyperlinks()
+}