pub fn supports_term_progress(is_terminal: bool) -> bool {
let windows_terminal = std::env::var("WT_SESSION").is_ok();
let conemu = std::env::var("ConEmuANSI").ok() == Some("ON".into());
let wezterm = std::env::var("TERM_PROGRAM").ok() == Some("WezTerm".into());
let ghostty = std::env::var("TERM_PROGRAM").ok() == Some("ghostty".into());
let iterm = std::env::var("TERM_PROGRAM").ok() == Some("iTerm.app".into())
&& std::env::var("TERM_FEATURES")
.ok()
.map(|v| term_features_has_progress(&v))
.unwrap_or(false);
let ptyxis = std::env::var("PTYXIS_VERSION")
.ok()
.and_then(|version| version.split(".").next()?.parse::<i32>().ok())
.map(|major_version| major_version >= 48)
.unwrap_or(false);
(windows_terminal || conemu || wezterm || ghostty || iterm || ptyxis) && is_terminal
}
fn term_features_has_progress(value: &str) -> bool {
let mut current = String::new();
for ch in value.chars() {
if !ch.is_ascii_alphanumeric() {
break;
}
if ch.is_ascii_uppercase() {
if current == "P" {
return true;
}
current.clear();
current.push(ch);
} else {
current.push(ch);
}
}
current == "P"
}
#[cfg(test)]
mod tests {
use super::term_features_has_progress;
#[test]
fn term_features_progress_detection() {
assert!(term_features_has_progress("MBT2ScP"));
assert!(!term_features_has_progress("MBT2Sc"));
}
}