๐Ÿ–จ๏ธ esc/pos implementation in gleam
Gleam 100.0%
31 3 4

Clone this repository

https://tangled.org/okk.moe/escpos https://tangled.org/did:plc:jwgnraovgs3eeenh23tlllyk/escpos
git@tangled.org:okk.moe/escpos git@tangled.org:did:plc:jwgnraovgs3eeenh23tlllyk/escpos

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
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, line, styled, text, Center}
import escpos/printer

pub fn main() {
  let assert Ok(printer) = printer.device("/dev/usb/lp0")

  document.render([
    styled([justify(Center), bold()], [
      line([text("Receipt")]),
    ]),
    line([text("Item 1 ... $5.00")]),
    line([text("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.device("/dev/usb/lp0")

  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.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 dev   # Experiment with a printer
gleam test  # Run the tests

Todo#

  • Some way to justify between text, work in justify-between branch