|
1 | 1 | /// Determines whether the terminal supports ANSI OSC 9;4. |
2 | 2 | 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 | + |
14 | 34 | // Ptyxis added OSC 9;4 support in 48.0. |
15 | 35 | // See https://gitlab.gnome.org/chergert/ptyxis/-/issues/305 |
16 | 36 | let ptyxis = std::env::var("PTYXIS_VERSION") |
17 | 37 | .ok() |
18 | 38 | .and_then(|version| version.split(".").next()?.parse::<i32>().ok()) |
19 | 39 | .map(|major_version| major_version >= 48) |
20 | 40 | .unwrap_or(false); |
| 41 | + if ptyxis { |
| 42 | + return true; |
| 43 | + } |
21 | 44 |
|
22 | | - (windows_terminal || conemu || wezterm || ghostty || iterm || ptyxis) && is_terminal |
| 45 | + false |
23 | 46 | } |
24 | 47 |
|
25 | 48 | // For iTerm, the TERM_FEATURES value "P" indicates OSC 9;4 support. |
| 49 | +// |
26 | 50 | // Context: https://iterm2.com/feature-reporting/ |
27 | 51 | fn term_features_has_progress(value: &str) -> bool { |
28 | 52 | let mut current = String::new(); |
|
0 commit comments