#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![deny(missing_docs)]
pub const REFERENCE: &str = include_str!("../README.md");
pub mod epos;
mod escpos;
pub mod webprnt;
mod xml;
use std::fmt;
pub const MAX_DOCUMENT_BYTES: usize = 8 * 1024 * 1024;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct PrintRequest {
pub escpos: Vec<u8>,
pub warnings: Vec<String>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DialectError(String);
impl DialectError {
pub(crate) fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
}
impl fmt::Display for DialectError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for DialectError {}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct PrinterStatus {
pub online: bool,
pub cover_open: bool,
pub paper_end: bool,
pub paper_near_end: bool,
pub drawer_pin3_high: bool,
}
impl PrinterStatus {
pub fn from_dle_eot(printer: u8, offline_cause: u8, paper: u8) -> Self {
Self {
online: printer & 0x08 == 0,
drawer_pin3_high: printer & 0x04 != 0,
cover_open: offline_cause & 0x04 != 0,
paper_end: paper & 0x60 != 0,
paper_near_end: paper & 0x0C != 0,
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Outcome {
Printed,
PaperEnd,
CoverOpen,
Timeout,
BadDocument(String),
DeviceNotFound,
}
impl Outcome {
pub fn after_print(status: &PrinterStatus) -> Self {
if status.paper_end {
Outcome::PaperEnd
} else if status.cover_open {
Outcome::CoverOpen
} else {
Outcome::Printed
}
}
pub fn printed(&self) -> bool {
matches!(self, Outcome::Printed)
}
}