escpos

A low-level imperative API for building ESC/POS printer commands.

This module provides a builder-style interface where each function takes a CommandBuffer and returns a modified buffer. For a declarative alternative, see escpos/document.

Example

import escpos.{Center, Left}
import escpos/printer

escpos.new()
|> escpos.reset()
|> escpos.align(Center)
|> escpos.bold(True)
|> escpos.writeln("Receipt")
|> escpos.bold(False)
|> escpos.align(Left)
|> escpos.writeln("Item 1 ... $5.00")
|> escpos.cut()
|> printer.print(my_printer)

Types

Printer font. Re-exported from escpos/protocol.

pub type Font =
  protocol.Font

Text justification. Re-exported from escpos/protocol.

pub type Justify =
  protocol.Justify

Values

pub fn align(
  cb: @internal CommandBuffer,
  justify: protocol.Justify,
) -> @internal CommandBuffer

Sets text alignment (Left, Center, or Right).

pub fn bold(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables bold text.

pub fn cut(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Performs a full paper cut.

pub fn double_strike(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables double-strike text.

pub fn flip(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables 180-degree rotation.

pub fn font(
  cb: @internal CommandBuffer,
  font: protocol.Font,
) -> @internal CommandBuffer

Sets the printer font.

pub fn image(
  cb: @internal CommandBuffer,
  image: image.PrintableImage,
) -> @internal CommandBuffer

Prints a monochrome image prepared by the image module.

Example

let assert Ok(pgm) = simplifile.read_bits(from: "./lucy.pgm")
let assert Ok(img) = image.from_pgm(raw_pgm)
let img = image.dither_bayer4x4(img, 0)

escpos.new()
|> escpos.image(img)
|> printer.print(printer)
pub fn line_feed(
  cb: @internal CommandBuffer,
  lines: Int,
) -> @internal CommandBuffer

Feeds the specified number of lines.

pub fn new() -> @internal CommandBuffer

Creates a new empty command buffer.

pub fn new_line(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Appends a single newline.

pub fn partial_cut(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Performs a partial paper cut, leaving a small portion connected.

pub fn raw(
  cb: @internal CommandBuffer,
  data: BitArray,
) -> @internal CommandBuffer

Appends raw bytes to the buffer.

pub fn reset(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Resets the printer to its initial state.

pub fn reset_font(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Resets the font to the default (FontA).

pub fn reset_text_size(
  cb: @internal CommandBuffer,
) -> @internal CommandBuffer

Resets text size to normal (1x1).

pub fn reverse(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables reverse (white on black) text.

pub fn smooth(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables character smoothing.

pub fn text_size(
  cb: @internal CommandBuffer,
  width: Int,
  height: Int,
) -> @internal CommandBuffer

Sets text size multiplier (1-8 for width and height).

pub fn underline(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables underlined text.

pub fn upside_down(
  cb: @internal CommandBuffer,
  b: Bool,
) -> @internal CommandBuffer

Enables or disables upside-down text.

pub fn write(
  cb: @internal CommandBuffer,
  text: String,
) -> @internal CommandBuffer

Writes text to the buffer.

pub fn writeln(
  cb: @internal CommandBuffer,
  text: String,
) -> @internal CommandBuffer

Writes text to the buffer followed by a newline.

Search Document