🖨️ esc/pos implementation in gleam
Gleam 100%

README.md

escpos #

Package Version Hex Docs

ESC/POS library for Gleam.

Implements a subset of ESC/POS commands for controlling receipt printers.

ESC/POS Specification

gleam add escpos@1

Usage #

Declarative API #

The escpos/document module provides a high-level declarative API:

import escpos/document.{bold, cut, justify, styled, writeln, Center}
import escpos/printer

pub fn main() {
  let assert Ok(printer) = printer.connect("192.168.1.100", 9100)

  document.build([
    styled([justify(Center), bold()], [
      writeln("Receipt"),
    ]),
    writeln("Item 1 ... $5.00"),
    writeln("Item 2 ... $3.50"),
    cut(),
  ])
  |> printer.print(printer)
}

Imperative API #

The escpos module provides a lower-level builder-style API:

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

pub fn main() {
  let assert Ok(printer) = printer.connect("192.168.1.100", 9100)

  escpos.new()
  |> escpos.reset()
  |> escpos.set_align(Center)
  |> escpos.set_bold(True)
  |> escpos.writeln("Receipt")
  |> escpos.set_bold(False)
  |> escpos.set_align(Left)
  |> escpos.writeln("Item 1 ... $5.00")
  |> escpos.writeln("Item 2 ... $3.50")
  |> escpos.line_feed(3)
  |> escpos.cut()
  |> printer.print(printer)
}

Further documentation can be found at https://hexdocs.pm/escpos.

Development #

gleam run   # Run the project
gleam test  # Run the tests