Skip to content

Thermal Parser

zachzurn edited this page Sep 28, 2024 · 2 revisions

This crate parses ESC/POS commands from binary data. It's designed purely as a parser without rendering capabilities.

This crate can also parse the human readable thermal format. See Thermal File format page

//See the resources/test folder for sample binary files
let bytes = std::fs::read("./thermal_test.bin".to_string()).unwrap();

//Create a context to store changes in text and graphic styles
let context = Context::new();

//Create a closure to handle parsed commands
let on_new_command = move |cmd: Command| {
    if debug { println!("{}", cmd.handler.debug(&cmd, &context)) };
};

//Create a new parser with the esc/pos command set
let mut command_parser = thermal_parser::new_esc_pos_parser(Box::from(on_new_command));

//Parse the bytes (Commands will be sent to the closure above)
command_parser.parse_bytes(&bytes);
Clone this wiki locally