feat(vt): port Ghostty's VT parsing layer
Ports the parsing half of ZIG/src/terminal into the ghostty-vt crate: - Parser state machine with a compile-time generated parse table and the UTF-8 decoder - OSC parser incl. all sub-parsers (titles, colors, clipboard, hyperlinks, semantic prompts/OSC 133, OSC 9 / ConEmu, iTerm2, kitty clipboard, color and text-sizing protocols, context signals) - CSI, SGR, modes table with save/restore, charsets, ansi, device status, mouse shapes, APC, DCS (incl. XTGETTCAP), tmux control-mode parser - color palette / X11 color names, kitty color and graphics command parser Deviations from Zig (documented in docs/rewrite/notes/ghostty-vt-W*.md): parser actions own their payloads instead of borrowing parser buffers; OSC strings are Vec<u8>; non-exhaustive Zig enums gain an Other(raw) variant; tmux regexes replaced by equivalent hand-written matchers. Known follow-up: semantic_prompt.rs carries local copies of the printf-q and percent decoders that belong in ghostty-os. Test Plan: - cargo test -p ghostty-vt: 395 passed, 1 ignored (skipped in Zig too) - cargo clippy -p ghostty-vt --all-targets -- -D warnings: clean
This commit is contained in:
1 parent
864ef82acb
commit
b2b248e003
44 files changed
+15040
-6
No files matched your search
@@ -0,0 +1,51 @@
|
||||
//! OSC 777 (ZIG/src/terminal/osc/parsers/rxvt_extension.zig).
|
||||
use crate::osc::{Command, Parser, State};
|
||||
|
||||
/// Parse OSC 777
|
||||
pub fn parse(parser: &mut Parser, _terminator_ch: Option<u8>) -> Option<Command> {
|
||||
let data = parser.data()?;
|
||||
let Some(k) = data.iter().position(|&b| b == b';') else {
|
||||
parser.state = State::Invalid;
|
||||
return None;
|
||||
};
|
||||
let ext = &data[..k];
|
||||
if ext != b"notify" {
|
||||
log::warn!("unknown rxvt extension: {}", String::from_utf8_lossy(ext));
|
||||
parser.state = State::Invalid;
|
||||
return None;
|
||||
}
|
||||
let Some(t) = data[k + 1..]
|
||||
.iter()
|
||||
.position(|&b| b == b';')
|
||||
.map(|i| i + k + 1)
|
||||
else {
|
||||
log::warn!("rxvt notify extension is missing the title");
|
||||
parser.state = State::Invalid;
|
||||
return None;
|
||||
};
|
||||
Some(Command::ShowDesktopNotification {
|
||||
title: data[k + 1..t].to_vec(),
|
||||
body: data[t + 1..].to_vec(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn osc_777_show_desktop_notification_with_title() {
|
||||
let mut p = Parser::init(false);
|
||||
for c in b"777;notify;Title;Body" {
|
||||
p.next(*c);
|
||||
}
|
||||
assert_eq!(
|
||||
p.end(Some(0x1b)).unwrap(),
|
||||
Command::ShowDesktopNotification {
|
||||
title: b"Title".to_vec(),
|
||||
body: b"Body".to_vec()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user