tables/
tables.rs

1use escpos_rust::{Printer, PrinterProfile, command::Font};
2
3fn main() {
4    let printer_profile = PrinterProfile::terminal_builder().with_font_width(Font::FontA, 20).build();
5    // We pass it to the printer
6    let mut printer = match Printer::new(printer_profile) {
7        Ok(maybe_printer) => match maybe_printer {
8            Some(printer) => printer,
9            None => panic!("No printer was found :(")
10        },
11        Err(e) => panic!("Error: {}", e)
12    };
13    // We set word splitting
14    printer.set_space_split(true);
15    
16    println!("Table with two columns:");
17    match printer.duo_table(("Product", "Price"), vec![
18        ("Milk", "5.00"),
19        ("Cereal", "10.00")
20    ]) {
21        Ok(_) => (),
22        Err(e) => println!("Error: {}", e)
23    }
24
25    println!("Table with three columns:");
26    match printer.trio_table(("Product", "Price", "Qty."), vec![
27        ("Milk", "5.00", "3"),
28        ("Cereal", "10.00", "1")
29    ]) {
30        Ok(_) => (),
31        Err(e) => println!("Error: {}", e)
32    }
33}