Phase 1 of docs/plans/formatters.md: single and double CP437 boxes from
one /print element, and a way to see a receipt without using paper.
- receipt: box, rule and kv elements, laid out when the job renders from
the printer profile, size and font (never fixed widths). Boxes take a
title (inline or capped), a footer, padding, fit and columns, and a
body of text or children (text, feed, kv, and rules as dividers joined
to the borders). Glyphs a code page lacks fall back per set: double-h
and double-v to double, then single, then ascii; a missing junction
switches line weight first.
- Validation names nested elements (elements[0].children[3] (qr)),
checks fields per block type, allows one level of children and counts
them toward the 500-element limit. Block fields on the older types are
problems, as they were unknown fields before.
- Text is composed to NFC and characters the code page lacks fold to
look-alikes (curly quotes, dashes, ellipsis, arrows, check marks, euro,
trademark), as the owner approved on 2026-11-29. An emoji sequence
prints as one '?'. Encodable text is untouched.
- escpos: CodePage.CanEncode and Decode, and Interpret, which reads a
command stream back as the printer would print it. It takes the
profile so that it can follow the printer's own wrapping and
alignment; raw spans stay opaque.
- POST /api/v1/preview and `uberbringer preview` show the lines a job
prints, as text or JSON with styles, without fetching images.
- Config: [format] max_lines (default 2000), refused with 422
too_many_lines on preview; printer.box_line_spacing (default 0).
Byte compatibility: testdata/compat fixtures were rendered by 9b91109
before the renderer changed, and still match it and the new renderer.
examples/blocks.json was printed on the TM-T88IV; the owner judged the
border gaps at the default spacing fine (2026-11-30), so
box_line_spacing stays 0, and TestPaperReceipts pins its bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9.0 KiB
9.0 KiB
Überbringer: design
Status: version 0.2.0, checked on paper on the TM-T88IV. Next is the
formatters work in docs/plans/formatters.md. This page records why the
daemon is shaped as it is. README.md describes how to use it.
Why
Scripts and services on the owner's network send short JSON jobs, and one
Epson receipt printer prints them. The daemon replaces the 0.1 one on the
same endpoint, POST /api/v1/print behind nginx, and 0.1 installs are
deployed. It is one static binary with no database, sized for receipt rates
on one printer.
client ─HTTPS─▶ nginx ─▶ server ── validate ──▶ printqueue (memory, 1 worker)
│ │ receipt.Render: whole job
│ │ to bytes, images via safehttp
│ ▼
└─ /healthz ──────▶ printer.Client ─TCP 9100─▶ printer
(one connection at a time)
Decisions
- One printer per instance. The config names one printer, and its client holds one connection to it at a time, shared by sends and status reads. A second printer means a second instance with its own config and port. The planned TM-T88VII and TM-m50II (owner, 2026-11-29) have the same geometry as the TM-T88IV, so a single profile default covers all three.
- The queue lives in memory, on purpose. ESC/POS gives no
acknowledgement of what has printed. A queue replayed after a crash could
therefore print a receipt twice. A lost job, by contrast, shows as failed
or unknown, and the client can send it again. Waiting jobs are marked
failed at shutdown. After a crash their IDs answer
job_not_found. One worker keeps jobs in submission order, and the history is capped byqueue.history. - Render, then send. The handler validates the whole job, and a
400lists every problem. The worker then renders the complete receipt, images included, to one byte stream that starts with a printer reset (ESC @). It sends that stream over one connection. A failure before the send, such as a broken image, costs no paper and leaves no half-printed receipt. A retry resends the same bytes and does not render again. A send that fails part-way can print part of a receipt twice. That is accepted, because retries are what let a job survive a printer that is briefly offline. - Text in, code page out. Clients send UTF-8, which is transcoded to
printer.codepage. The default is CP437, for the box drawing and shading the owner prints (owner, 2026-11-29). Control characters are stripped, so data can never become a printer command. Only therawelement sends bytes as given.- Before wrapping, text is composed to NFC, and characters the code page
lacks fold to ASCII look-alikes (curly quotes, dashes, the ellipsis and
a few symbols). An emoji sequence prints as one
?(owner, 2026-11-29). A fold applies only where the code page lacks the character, so cp1252 keeps its curly quotes. After this step one rune is one column and one byte, which is what wrap counts.
- Before wrapping, text is composed to NFC, and characters the code page
lacks fold to ASCII look-alikes (curly quotes, dashes, the ellipsis and
a few symbols). An emoji sequence prints as one
- Blocks are laid out when the job renders.
box,ruleandkvtake their width from the profile (orprinter.columns) and their own size and font, never from fixed numbers, so a job stays printer-neutral. Layout never fails on a valid job: widths clamp, titles and labels are cut with..., and a box narrower than its padding gives up the padding. The only render-time failure added isformat.max_lines. Validation stays structural, because geometry depends on the printer.- Glyphs the code page lacks fall back per glyph set:
double-handdouble-vtodouble, thensingle, thenascii. A divider junction the page lacks switches to the other line weight first, and a capped title on double lines uses╣ ╠, which cp850 has, instead of╡ ╞. - Block fields are rejected on the older element types, which otherwise stay lenient, so a block field sent to the wrong type still fails as an unknown field did before blocks existed.
- Boxes print at the printer's default line spacing. The small gaps that
leaves in vertical borders were judged acceptable on the TM-T88IV
(owner, 2026-11-30), so
printer.box_line_spacingstays 0 by default. The bytes of that calibration receipt,examples/blocks.json, are pinned in a receipt test.
- Glyphs the code page lacks fall back per glyph set:
- The preview reads the bytes back.
escpos.Interpretparses the stream the renderer produced, so the preview and the tests show what the printer receives rather than what the layout meant. It simulates the printer's own wrapping and alignment, which needs the profile.rawbytes stay opaque, since arbitrary bytes cannot be parsed reliably, and images are blank placeholders, so a preview never fetches anything. - Profiles set the layout, and the default is the narrower one. Columns
are the profile's dots per line divided by the glyph width; nothing
hard-codes 42 or 512. The first paper test ran the 576-dot
tm-t20profile on the TM-T88IV, which has 512 dots, and the printer broke words at its own edge (seve/ral). A profile wider than the printer breaks words, while a narrower one only shortens lines. Sotm-t88(512 dots, 42 columns) is the default. - Status is read in a way that tolerates a busy printer.
/healthzsends DLE EOT 1 to 4 over the same connection slot that sends use.- The DLE EOT 2 bits (cover open, paper-end stop) are cleared while DLE EOT 1 says online. Epson printers go offline for both causes, and a TM-T88IV reported a stale cover-open bit while cutting.
- A not-ready reading is re-read 750 ms later.
- A read cut short by our own deadline is
timeoutwith503. It never counts as "status unsupported", because an unknown state must not look healthy. - A printer that never answers status gets
200unknown. - The TM-T88VII does not report paper near-end through DLE EOT 4.
- Health is for monitors.
/healthzanswers200when the printer is ready, or when it cannot report status. It answers503when a job could not print now: the printer is unreachable, not ready or timed out. A503from it is a refusal: it is logged at WARN by the request line and never sent to Sentry. - Images are fetched by the worker, through an SSRF guard. A slow or
broken image URL holds no HTTP request and shows up as a
failedjob.safehttpchecks the resolved address at connect time, so DNS rebinding and redirects cannot reach loopback, private, link-local or cloud metadata addresses. Exceptions are configured explicitly (images.*). Time, size, pixel and height limits bound each image. - Errors are flat JSON with a stable code. The shape is
{"error", "code", "details"}.codeis the contract with clients, anderroris for people. A refusal is answered and never logged as a failure. An unexpected error or panic is logged once and reported to Sentry once, without the body or theAuthorizationheader. - What stays compatible with 0.1. The endpoint, the HS256 tokens and the
config keys stay as they were. The 0.1 body and its plain-text answer do
not. A 0.1 body gets a
400that points to the migration table, instead of being translated. Tokens are read only from the header, because tokens in query strings end up in proxy logs. - Stack choices (owner, 2026-11-29):
- Fiber v3 instead of Echo.
- TypeID (UUIDv7) job and request IDs instead of snowflakes. They sort by time and need no node configuration.
- An Alpine Docker image.
- Packaging. The release tarballs are built for linux amd64, armv6, armv7
and arm64.
install.shsets up nginx (TLS,X-Real-IP), acme.sh and the sandboxed unit frompackaging/. The daemon binds 127.0.0.1 by default and serves no TLS itself.
Planned: formatters
Modules, ntfy among them, that turn plain input into receipts built from the
blocks. The plan is docs/plans/formatters.md; its first phase, the blocks
and the preview, is built. Decided so far (owner, 2026-11-29):
- ntfy is an input: its notifications are printed. The server is self-hosted at a public URL, the subscriber authenticates with a token, and attachments come from a public host, so image fetches need no private-network exception.
- Which priorities print is configurable per subscription. By default every priority prints, and priorities 1 and 2 print in a compact form.
- Labels are in English. The footer's time zone and date format come from the config.
Deferred
- Paper near-end on the TM-T88VII, which
GS r 1reports. Add it when that printer arrives. - Several printers from one instance, through routing or a pool. Until then, run one instance per printer.
- A durable queue. It needs a way to tell which receipts printed before a crash.
- Printer alerts sent out to ntfy (paper out, cover open). They have not been requested. Printing incoming ntfy messages is part of the formatters plan.