1 个不稳定版本

0.1.0 2022年7月7日

#2176 in 编码

Download history 914/week @ 2024-04-10 1114/week @ 2024-04-17 1093/week @ 2024-04-24 1097/week @ 2024-05-01 792/week @ 2024-05-08 807/week @ 2024-05-15 980/week @ 2024-05-22 934/week @ 2024-05-29 954/week @ 2024-06-05 922/week @ 2024-06-12 944/week @ 2024-06-19 727/week @ 2024-06-26 687/week @ 2024-07-03 679/week @ 2024-07-10 819/week @ 2024-07-17 647/week @ 2024-07-24

2,956 每月下载量
3 个crate中使用 (2 个直接使用)

MIT 许可证

52KB
1.5K SLoC

六色分词器

这是一个序列化六色图像的分词器,有关协议的更多信息,请参阅:https://vt100.net/docs/vt3xx-gp/chapter14.html

Parser 应按顺序逐个提供六色字节和一个回调函数。当相关时,回调函数将使用 SixelEvent 0 次或多次调用每字节。

示例

use sixel_tokenizer::Parser;

fn main() {
    let sample = "
        \u{1b}Pq
        \"2;1;100;200
        #0;2;0;0;0#1;2;100;100;0#2;2;0;100;0
        #1~~@@vv@@~~@@~~$
        #2??}}GG}}??}}??-
        #1!14@
        \u{1b}\\
    ";
    let sample_bytes = sample.as_bytes();
    let mut events = vec![];
    let mut parser = Parser::new();
    for byte in sample_bytes {
        parser.advance(&byte, |sixel_event| events.push(sixel_event));
    }
    let mut snapshot = String::new();
    for event in events {
        snapshot.push_str(&format!("{:?}", event));
        snapshot.push('\n');
    }
    println!("{}", snapshot);
}

此程序将打印

Dcs { macro_parameter: None, transparent_background: None, horizontal_pixel_distance: None }
RasterAttribute { pan: 2, pad: 1, ph: Some(100), pv: Some(200) }
ColorIntroducer { color_number: 0, color_coordinate_system: Some(RGB(0, 0, 0)) }
ColorIntroducer { color_number: 1, color_coordinate_system: Some(RGB(100, 100, 0)) }
ColorIntroducer { color_number: 2, color_coordinate_system: Some(RGB(0, 100, 0)) }
ColorIntroducer { color_number: 1, color_coordinate_system: None }
Data { byte: 126 }
...
GotoNextLine
ColorIntroducer { color_number: 1, color_coordinate_system: None }
Repeat { repeat_count: 14, byte_to_repeat: 64 }
End

许可证

MIT

依赖项

~330–790KB
~18K SLoC