use std::io::{self, Write};
mod diacritics;
pub use diacritics::KITTY_PLACEHOLDER_DIACRITICS;
pub fn write_sixel<W: Write>(
w: &mut W,
p1: i32,
p2: i32,
p3: i32,
payload: &[u8],
) -> io::Result<()> {
w.write_all(b"\x1bP")?;
if p1 >= 0 {
write!(w, "{p1}")?;
}
w.write_all(b";")?;
if p2 >= 0 {
write!(w, "{p2}")?;
}
if p3 > 0 {
write!(w, ";{p3}")?;
}
w.write_all(b"q")?;
w.write_all(payload)?;
w.write_all(b"\x1b\\")
}
pub fn write_kitty_graphics<W: Write>(
w: &mut W,
options: &[&str],
payload: &[u8],
) -> io::Result<()> {
w.write_all(b"\x1b_G")?;
for (i, opt) in options.iter().enumerate() {
if i > 0 {
w.write_all(b",")?;
}
w.write_all(opt.as_bytes())?;
}
if !payload.is_empty() {
w.write_all(b";")?;
w.write_all(payload)?;
}
w.write_all(b"\x1b\\")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_sixel_minimal() {
let mut buf = Vec::new();
write_sixel(&mut buf, 0, 1, 0, b"#0;2;0;0;0").unwrap();
assert_eq!(buf, b"\x1bP0;1q#0;2;0;0;0\x1b\\");
}
#[test]
fn test_kitty_graphics() {
let mut buf = Vec::new();
write_kitty_graphics(&mut buf, &["a=T", "f=32", "s=10", "v=20"], b"AAAA").unwrap();
assert_eq!(buf, b"\x1b_Ga=T,f=32,s=10,v=20;AAAA\x1b\\");
}
}