|
|
@ -23,13 +23,33 @@ use std::{
|
|
|
|
fmt,
|
|
|
|
fmt,
|
|
|
|
io::{self, Write},
|
|
|
|
io::{self, Write},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
use termini::TermInfo;
|
|
|
|
|
|
|
|
|
|
|
|
fn term_program() -> Option<String> {
|
|
|
|
fn term_program() -> Option<String> {
|
|
|
|
std::env::var("TERM_PROGRAM").ok()
|
|
|
|
// Some terminals don't set $TERM_PROGRAM
|
|
|
|
|
|
|
|
match std::env::var("TERM_PROGRAM") {
|
|
|
|
|
|
|
|
Err(_) => std::env::var("TERM").ok(),
|
|
|
|
|
|
|
|
Ok(term_program) => Some(term_program),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn vte_version() -> Option<usize> {
|
|
|
|
fn vte_version() -> Option<usize> {
|
|
|
|
std::env::var("VTE_VERSION").ok()?.parse().ok()
|
|
|
|
std::env::var("VTE_VERSION").ok()?.parse().ok()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reset_cursor_approach(terminfo: TermInfo) -> String {
|
|
|
|
|
|
|
|
let mut reset_str = "\x1B[0 q".to_string();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(termini::Value::Utf8String(se_str)) = terminfo.extended_cap("Se") {
|
|
|
|
|
|
|
|
reset_str.push_str(se_str);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_str.push_str(
|
|
|
|
|
|
|
|
terminfo
|
|
|
|
|
|
|
|
.utf8_string_cap(termini::StringCapability::CursorNormal)
|
|
|
|
|
|
|
|
.unwrap_or(""),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reset_str
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Describes terminal capabilities like extended underline, truecolor, etc.
|
|
|
|
/// Describes terminal capabilities like extended underline, truecolor, etc.
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
@ -69,10 +89,7 @@ impl Capabilities {
|
|
|
|
|| t.extended_cap("Su").is_some()
|
|
|
|
|| t.extended_cap("Su").is_some()
|
|
|
|
|| vte_version() >= Some(5102)
|
|
|
|
|| vte_version() >= Some(5102)
|
|
|
|
|| matches!(term_program().as_deref(), Some("WezTerm")),
|
|
|
|
|| matches!(term_program().as_deref(), Some("WezTerm")),
|
|
|
|
reset_cursor_command: t
|
|
|
|
reset_cursor_command: reset_cursor_approach(t),
|
|
|
|
.utf8_string_cap(termini::StringCapability::CursorNormal)
|
|
|
|
|
|
|
|
.unwrap_or("\x1B[0 q")
|
|
|
|
|
|
|
|
.to_string(),
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|