# escpos [![Package Version](https://img.shields.io/hexpm/v/escpos)](https://hex.pm/packages/escpos) [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/escpos/) ESC/POS library for Gleam. Implements a subset of ESC/POS commands for controlling receipt printers. [ESC/POS Specification](https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/commands.html) ```sh gleam add escpos@1 ``` ## Usage ### Declarative API The `escpos/document` module provides a high-level declarative API: ```gleam 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: ```gleam 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 . ## Development ```sh 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