This commit is contained in:
sxyazi 2024-07-26 22:40:57 +08:00
parent 60bef59598
commit f4a0ac4de3
No known key found for this signature in database
2 changed files with 13 additions and 16 deletions

View file

@ -130,7 +130,7 @@ impl Emulator {
RestorePosition RestorePosition
)?; )?;
let resp = futures::executor::block_on(Self::read_until_da1())?; let resp = futures::executor::block_on(Self::read_until_da1());
let names = [ let names = [
("kitty", Self::Kitty), ("kitty", Self::Kitty),
("Konsole", Self::Konsole), ("Konsole", Self::Konsole),
@ -189,7 +189,7 @@ impl Emulator {
result result
} }
pub async fn read_until_da1() -> Result<String> { pub async fn read_until_da1() -> String {
let mut buf: Vec<u8> = Vec::with_capacity(200); let mut buf: Vec<u8> = Vec::with_capacity(200);
let read = async { let read = async {
let mut stdin = BufReader::new(tokio::io::stdin()); let mut stdin = BufReader::new(tokio::io::stdin());
@ -214,6 +214,6 @@ impl Emulator {
Ok(Err(e)) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"), Ok(Err(e)) => error!("read_until_da1 failed: {buf:?}, error: {e:?}"),
Ok(Ok(())) => {} Ok(Ok(())) => {}
} }
String::from_utf8(buf).map_err(Into::into) String::from_utf8_lossy(&buf).into_owned()
} }
} }

View file

@ -36,19 +36,16 @@ impl Term {
mouse::SetMouse(true), mouse::SetMouse(true),
)?; )?;
if let Ok(s) = futures::executor::block_on(Emulator::read_until_da1()) { let da = futures::executor::block_on(Emulator::read_until_da1());
CSI_U.store(s.contains("\x1b[?0u"), Ordering::Relaxed); CSI_U.store(da.contains("\x1b[?0u"), Ordering::Relaxed);
BLINK.store(s.contains("\x1b[?12;1$y"), Ordering::Relaxed); BLINK.store(da.contains("\x1b[?12;1$y"), Ordering::Relaxed);
SHAPE.store( SHAPE.store(
s.split_once("\x1bP1$r") da.split_once("\x1bP1$r")
.and_then(|(_, s)| s.bytes().next()) .and_then(|(_, s)| s.bytes().next())
.filter(|&b| matches!(b, b'0'..=b'6')) .filter(|&b| matches!(b, b'0'..=b'6'))
.map_or(u8::MAX, |b| b - b'0'), .map_or(u8::MAX, |b| b - b'0'),
Ordering::Relaxed, Ordering::Relaxed,
); );
} else {
SHAPE.store(u8::MAX, Ordering::Relaxed);
}
if CSI_U.load(Ordering::Relaxed) { if CSI_U.load(Ordering::Relaxed) {
queue!( queue!(