Add the list block and the module layer with the note module
Security / Vulnerability check (push) Successful in 41s
Test / Lint and test (push) Successful in 1m50s

The list block prints items with a dot, dash, number or checkbox bullet,
wrapping a long item with a hanging indent; a checkbox list ticks its
done items as [√], or [x] on code pages without √. It stands alone or
inside a box, and its items, bullet and done fields carry their enums
and limits as jsonschema tags.

internal/pkg/modules holds modules that build ordinary jobs from their
own payloads: a registry by name, an Env with the clock, time zone and
time layout, strict payload decoding that reports every problem, ErrSkip
and PayloadError. The note module prints a boxed note with an optional
checklist and a time stamp in the footer.

Three routes join the route table: POST /api/v1/print/{module} and
POST /api/v1/preview/{module}, which take ?copies and a reserved
?printer, and GET /api/v1/modules. Print and the module route share one
submit path, and preview shares one too. New error codes:
invalid_payload, invalid_query, unknown_printer, module_not_found and
module_failed; a module that builds an invalid receipt is logged and
reported to Sentry once. [format] gains timezone and time_layout, the
binary embeds the time zone database, and uberbringer preview takes
--module.

The note receipt passed on the TM-T88IV, and its bytes are pinned in
TestPaperReceipts. docs/api.md describes the list block, the module
routes and the note payload; docs/swagger.json is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 10:55:50 -06:00
1 parent 6b2e402f1a
commit 3e9779f71a
69 files changed
+3092 -262

No files matched your search

+32 -17
View File
@@ -20,8 +20,8 @@ import (
// job.
var ErrTrailingData = errors.New("trailing data after the job")
// Element types. Box, rule and kv are blocks: they are laid out to the
// paper width when the job is rendered.
// Element types. Box, rule, kv and list are blocks: they are laid out to
// the paper width when the job is rendered.
const (
TypeText = "text"
TypeFeed = "feed"
@@ -33,6 +33,7 @@ const (
TypeBox = "box"
TypeRule = "rule"
TypeKV = "kv"
TypeList = "list"
)
// Job limits. MaxElements counts the children of boxes too.
@@ -40,6 +41,7 @@ const (
MaxElements = 500
MaxCopies = 5
MaxPairs = 100
MaxItems = 200
)
// Element defaults.
@@ -64,18 +66,19 @@ type Job struct {
}
// Element is one item on a receipt. Its type selects which fields apply. On
// the blocks (box, rule and kv) and inside a box, a field that does not
// apply is an error; on the other types it is ignored, except for the block
// fields. width and height mean character multipliers for text, module width
// and bar height for barcodes, and target width in dots for images. A
// block's width is set by columns, in characters of its own size and font,
// never by width; without columns a block spans the line. The enums list
// the canonical spellings: apart from type and leader, other letter case is
// accepted too, and so are a few aliases such as centre and ean-13.
// the blocks (box, rule, kv and list) and inside a box, a field that does
// not apply is an error; on the other types it is ignored, except for the
// block fields. width and height mean character multipliers for text,
// module width and bar height for barcodes, and target width in dots for
// images. A block's width is set by columns, in characters of its own size
// and font, never by width; without columns a block spans the line. The
// enums list the canonical spellings: apart from type and leader, other
// letter case is accepted too, and so are a few aliases such as centre and
// ean-13.
type Element struct {
// Type is the kind of element. box, rule and kv are blocks, laid out to
// the printer model's width when the job prints.
Type string `json:"type" jsonschema:"required,enum=text,enum=feed,enum=qr,enum=barcode,enum=image,enum=raw,enum=cut,enum=box,enum=rule,enum=kv"`
// Type is the kind of element. box, rule, kv and list are blocks, laid
// out to the printer model's width when the job prints.
Type string `json:"type" jsonschema:"required,enum=text,enum=feed,enum=qr,enum=barcode,enum=image,enum=raw,enum=cut,enum=box,enum=rule,enum=kv,enum=list"`
// Text is a text element's UTF-8 text, a box's body or a rule's label.
// \n starts a new line.
@@ -138,7 +141,7 @@ type Element struct {
Mode string `json:"mode,omitempty" jsonschema:"enum=partial,enum=full"`
// Children are a box's body as elements, one level deep: text, feed,
// rule and kv. Set text or children, not both.
// rule, kv and list. Set text or children, not both.
Children []Element `json:"children,omitempty"`
// Title is text set into a box's top border.
Title string `json:"title,omitempty"`
@@ -165,6 +168,15 @@ type Element struct {
// Leader is the fill between a kv row's key and value: ".", the
// default, "·", " " (or "space"), "_", "-" or "─".
Leader string `json:"leader,omitempty" jsonschema:"enum=.,enum=·,enum= ,enum=space,enum=_,enum=-,enum=─"`
// Items are a list's items, 1-200, none empty; required for list. An
// item too long for its line wraps with a hanging indent.
Items []string `json:"items,omitempty" jsonschema:"minItems=1,maxItems=200,minLength=1"`
// Bullet marks each item of a list: dot, the default, dash, number
// (right-aligned to the widest number) or checkbox.
Bullet string `json:"bullet,omitempty" jsonschema:"enum=dot,enum=dash,enum=number,enum=checkbox"`
// Done are the indexes into items, from 0, of a checkbox list's ticked
// items, each once. They print as [√], or [x] on code pages without √.
Done []int `json:"done,omitempty" jsonschema:"uniqueItems=true,minimum=0,maximum=199"`
}
// Pair is one row of a kv block: a key, a leader and a value.
@@ -258,13 +270,13 @@ func (el Element) problems(path string, inBox bool) []string {
func (el Element) validate(inBox bool) []string {
if inBox {
switch el.Type {
case TypeText, TypeFeed, TypeRule, TypeKV:
case TypeText, TypeFeed, TypeRule, TypeKV, TypeList:
case TypeBox, TypeQR, TypeBarcode, TypeImage, TypeRaw, TypeCut:
return []string{"not allowed inside a box; place it after the box"}
case "":
return []string{"type is required"}
default:
return []string{fmt.Sprintf("unknown type %q (inside a box, want text, feed, rule or kv)", el.Type)}
return []string{fmt.Sprintf("unknown type %q (inside a box, want text, feed, rule, kv or list)", el.Type)}
}
}
problems := el.checkFields(inBox)
@@ -294,10 +306,13 @@ func (el Element) validate(inBox bool) []string {
case TypeKV:
_, err = el.kvSpec()
problems = append(problems, el.pairProblems()...)
case TypeList:
_, err = el.listSpec()
problems = append(problems, el.itemProblems()...)
case "":
err = fmt.Errorf("type is required")
default:
err = fmt.Errorf("unknown type %q (want text, feed, qr, barcode, image, raw, cut, box, rule or kv)", el.Type)
err = fmt.Errorf("unknown type %q (want text, feed, qr, barcode, image, raw, cut, box, rule, kv or list)", el.Type)
}
if err != nil {
problems = append(problems, err.Error())