Skip to content

Commit 09b7457

Browse files
authored
Merge pull request #306 from epage/support
fix(progress): Clean up terminal support detection
2 parents adf5873 + 883c575 commit 09b7457

1 file changed

Lines changed: 36 additions & 12 deletions

File tree

crates/anstyle-progress/src/query.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
11
/// Determines whether the terminal supports ANSI OSC 9;4.
22
pub fn supports_term_progress(is_terminal: bool) -> bool {
3-
let windows_terminal = std::env::var("WT_SESSION").is_ok();
4-
let conemu = std::env::var("ConEmuANSI").ok() == Some("ON".into());
5-
let wezterm = std::env::var("TERM_PROGRAM").ok() == Some("WezTerm".into());
6-
let ghostty = std::env::var("TERM_PROGRAM").ok() == Some("ghostty".into());
7-
// iTerm added OSC 9;4 support in v3.6.6, which we can check for.
8-
// For context: https://github.com/rust-lang/cargo/pull/16506#discussion_r2706584034
9-
let iterm = std::env::var("TERM_PROGRAM").ok() == Some("iTerm.app".into())
10-
&& std::env::var("TERM_FEATURES")
11-
.ok()
12-
.map(|v| term_features_has_progress(&v))
13-
.unwrap_or(false);
3+
if !is_terminal {
4+
return false;
5+
}
6+
7+
// Terminal feature detection, includes
8+
// - iTerm support in v3.6.6
9+
let term_features = std::env::var("TERM_FEATURES")
10+
.ok()
11+
.map(|v| term_features_has_progress(&v))
12+
.unwrap_or(false);
13+
if term_features {
14+
return true;
15+
}
16+
17+
// https://github.com/wezterm/wezterm/issues/6581
18+
// https://ghostty.org/docs/install/release-notes/1-2-0#graphical-progress-bars
19+
let term_program = std::env::var("TERM_PROGRAM").ok();
20+
if matches!(term_program.as_deref(), Some("WezTerm") | Some("ghostty")) {
21+
return true;
22+
}
23+
24+
// https://github.com/microsoft/terminal/pull/8055
25+
if std::env::var("WT_SESSION").is_ok() {
26+
return true;
27+
}
28+
29+
// https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
30+
if std::env::var("ConEmuANSI").ok() == Some("ON".into()) {
31+
return true;
32+
}
33+
1434
// Ptyxis added OSC 9;4 support in 48.0.
1535
// See https://gitlab.gnome.org/chergert/ptyxis/-/issues/305
1636
let ptyxis = std::env::var("PTYXIS_VERSION")
1737
.ok()
1838
.and_then(|version| version.split(".").next()?.parse::<i32>().ok())
1939
.map(|major_version| major_version >= 48)
2040
.unwrap_or(false);
41+
if ptyxis {
42+
return true;
43+
}
2144

22-
(windows_terminal || conemu || wezterm || ghostty || iterm || ptyxis) && is_terminal
45+
false
2346
}
2447

2548
// For iTerm, the TERM_FEATURES value "P" indicates OSC 9;4 support.
49+
//
2650
// Context: https://iterm2.com/feature-reporting/
2751
fn term_features_has_progress(value: &str) -> bool {
2852
let mut current = String::new();

0 commit comments

Comments
 (0)