Phases 1-4 of docs/plans/formatters.md are built and described in design.md, and every phase 5 item now has a plan of its own, under Planned next. So the plan goes, and what still matters moves into design.md. A new decision says that existing jobs keep their meaning and their bytes: /print stays strictly decoded, TestRenderCompat and TestPaperReceipts pin the bytes, and Renderer.Render is the only path to printer bytes. The labels and footer settings join "Modules build ordinary jobs". Deferred gains nested boxes and goldmark, and the geometry checks in the HTTP handler that stay rejected. The plan's other invariants were already design.md decisions. The plans that cited formatters.md now cite design.md, or drop the reference: job-store.md, printers.md, blocks.md and templates.md. job-store.md's phase 5 list moves to design.md's Deferred section once its other phases are done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 KiB
Plan: more blocks
Status: planned; nothing is built. The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item for more blocks records them. Each block is built when it is needed, one at a time, so the five stages are independent. Each runs alone in its own session, briefed from its section, in any order; the Overview suggests one. Decisions 2 and 3 apply to every stage, and decision 1 to stages 1-3, which add glyphs. Stage 1 follows decisions 4-6, stage 2 decisions 7-14, stage 3 decisions 15-17, stage 4 decisions 18-21 and stage 5 decisions 22-26. Every paper check needs the owner's OK. A stage's last commit deletes its section here, and moves the stage's decisions from that Planned next item into design.md's bullet "Blocks are laid out when the job renders". Whichever stage finishes last deletes this plan, its findings with it, and design.md's Planned next item for more blocks.
Decisions (owner, 2026-11-30)
- More blocks are planned as a feature of their own: a table (with
╤╪╧junctions), a banner, a group, inline spans and a custom rule character. - Each is built when it is needed, one at a time.
The owner accepted the details below on 2026-12-01. They are numbered, so the rest of the plan can refer to them.
For every stage:
- Glyphs the code page lacks. Each new glyph set falls back as the box styles do (glyphs.go:29-35):
double-handdouble-vtodouble, thensingle, thenascii. A set falls back whole when the code page lacks any of its glyphs, junctions included, asbordersForalready checks corners and lines (glyphs.go:40-57). A fallback is silent, as for boxes and rules; the preview shows the glyphs used. Investigation findings, GLYPHS BY CODE PAGE, lists what each page has.- cp858 is cp850 with
€in place ofı, so every box, junction and shade glyph is the same. The goldens stay in cp437, cp850 and cp1252 (golden_test.go:22). Each of stages 1-3 adds a unit test that its glyph choice on cp858 equals cp850's. - Trade-off: a user on cp850 who asks for
double-hgetsdoublewithout being told.
- cp858 is cp850 with
- Proving each block on paper. Each stage adds one or two short receipts,
examples/<block>.jsonand, where one would be long, a second. They show the new block's styles and edge cases. TestExampleJobs keeps every example valid with nothing printed as?(golden_test.go:62), so an example grows with the commits of its stage. With the owner's OK each prints on the TM-T88IV, one at a time. Once he passes one, its bytes are pinned in TestPaperReceipts (compat_test.go:100) astestdata/paper/<block>.hex, rendered with the cut feed it printed with (cutFeed: 3, the daemon's default). The pin folds into the stage's last feature commit (git commit --fixup, thengit rebase --autosquash main), whose body says it was checked on paper on the TM-T88IV.- Trade-off: one more pinned receipt per block, regenerated only after a new paper check.
- Modules. No module changes in these stages. A module's output is pinned on paper (
testdata/paper/ntfy-*.hex,note.hex), so changing it is a change of its own, with its own paper check, made when the owner asks. The candidates:- spans: the markdown subset keeps
**bold**as bold instead of dropping the marks (markdown.go:53); - banner: the urgent card's
URGENTheading, today a dark rule with a bold label (card.go:196); - table: a digest's rows, today text lines of time and title (digest.go:68).
- Trade-off: the new blocks first reach receipts only through
/print.
- spans: the markdown subset keeps
For stage 1, the rule character:
- The field and the characters it takes. A new field
charonrule, one character that repeats across the line in place of the style's pattern:{"type": "rule", "char": "*", "text": "TODAY"}. Validation is structural: exactly one rune as sent, which is not a control character, not a newline or tab, not a combining mark (Unicode Mn or Me), not a format character (Cf, such as the soft hyphen and the bidi controls) and not one of the invisible runesnormalizedrops (normalize.go:165-176). A space is allowed: a rule of spaces centres its label."char": ""means unset, as an empty string does on every other field, so the tag ismaxLength=1alone, which counts code points as validation does; TestBoundTagsMatchValidation learns to check a field with an upper bound only.- A decomposed
é, aneand a combining accent, is two runes and is refused, although NFC would compose it. Trade-off: a client must send composed text.
- A decomposed
- The fallback where the code page lacks the character. The character is composed to NFC first, as text is, so
Å(U+212B) becomesÅ(U+00C5). Then, in order, the character itself; its fold, when the fold is one character the page prints (•folds to·, normalize.go:26); then the pattern of the rule'sstyle, which defaults tosingleand itself ends in-(glyphs.go:98-108). So"char": "♦", "style": "double"prints═on cp850 and=on cp1252. Folds of several characters (→to->,€toEUR) are not used as patterns. The fallback counts no?, so the preview gives no warning.- Trade-off: a character the page lacks never prints as
?, so a client does not learn it fell back unless it reads the preview.
- Trade-off: a character the page lacks never prints as
- Inside a box.
charis refused on a divider inside a box (field "char" does not apply to rule inside a box). A divider joins the side borders with junctions (glyphs.go:77-94), and only─and═have junctions.- Trade-off: a card cannot have a
* * *divider.
- Trade-off: a card cannot have a
For stage 2, the table:
- The JSON shape. The names are those of decision 14:
{"type": "table", "style": "double-h", "cols": [{"head": "Item"}, {"head": "Qty", "align": "right"}, {"head": "Price", "align": "right"}], "rows": [["Flat white", "2", "7.00"], ["Almond croissant", "1", "3.50"]], "foot": [["Total", "3", "10.50"]]}colsdefines the columns, one object each:head(the header text, may be empty),align(left,centerorright; defaultleft),width(a fixed width in characters) andgrow(decision 9).rowsare the body, each an array of exactly as many strings ascols; a cell may be empty.footare rows printed after a separator, in bold, for totals.columns,size,font,paddingandfitmean what they mean on a box.- The header row prints, in bold, when any
headis not empty. - Trade-off: a row cannot be bold unless it is in
foot, and one table has one header.
- Borders.
styletakes the box styles,single,double,double-h,double-vandascii, and a newnone. The default isdouble-h, the look the owner named:╒═╤═╕,│,╞═╪═╡,╘═╧═╛. The header and foot separators use the frame's horizontal line, so adouble-htable has╞═╪═╡. No lines run between body rows.nonedraws no frame. Columns are separated by the blank cell where a vertical line would be, with the padding on each side, so the gap is 1 + 2 ×paddingspaces. The header and foot separators are a rule of─across the table,-where the page lacks it.- On cp850 and cp858,
double-handdouble-vprint asdouble(╔═╦═╗,╠═╬═╣,╚═╩═╝). On cp1252 every frame isascii:+at every corner and junction,-and|, and=for the separators when the style asked for double horizontal lines, as dividers do (glyphs.go:90-93). - Trade-off: the default differs from the box's,
single.
- Column widths. A column with
widthis fixed at that many characters; the others size by content. A column may setgrow, a weight from 1 to 10, to take spare room;growandwidthtogether are refused. Architecture, TABLE LAYOUT, gives the exact rule:- each auto column's least width is its longest word and its natural width its longest line, header included;
- widths are given out in rounds, fixed widths and least widths first, then natural widths, each round shared in proportion to what each column still wants;
- spare room goes to the columns with
growin proportion to it, or, when none hasgrow, to the first auto column, where receipts put the item's name. A table whose columns are all fixed shrinks to them and is centred. fit: trueshrinks the table to its natural width and centres it, as it does a box;columnsis then the most it may take.- Shares are whole characters, given by largest remainder, ties to the leftmost column, so a layout is the same on every run.
- A fixed width is what a column gets when the room allows. On a line too narrow for every column's want, a fixed column shrinks with the others, so the table still fits.
- Trade-off: a table whose widest column is not the first must say
grow.
- Wrapping in cells. Each cell wraps at spaces to its column's width with today's
wrap(layout.go:56-68);\nstarts a new paragraph; only a word longer than the column splits. A row is as tall as its tallest cell; the others are filled with blank lines below their text. Each line of a cell is aligned as its column; header cells too. Cells are normalised as box text is (blocklayout.go:33-37), tabs expanded from the cell's own left edge.- Trade-off: no vertical alignment other than top, and no alignment on a decimal point.
- When the columns do not fit the paper. Layout never fails on a valid job (design.md, "Blocks are laid out when the job renders"; invariant 2 here), so a table always prints. In order:
- Padding goes first, as a narrow box gives up its padding before its content (blocklayout.go:139-141). It drops, one step at a time, while the room is less than every column's want: its longest word, or less where its natural or fixed width is less.
- Each column needs its want counted up to 8 characters. While the room at padding 0 holds every column's need, the table keeps its columns, and only words longer than 8 characters can split.
- Below that, the table prints stacked: each row as key-value lines, the column's
headas the key and the cell as the value, laid out as a kv block is (blocklayout.go:386-410), with a.leader. Where a head would be cut, whichkvLinesdoes to a key longer than the width less 8, the whole table uses the narrow form instead: each head on a line of its own, the cell below it, right-aligned (blocklayout.go:475-490). A cell whose column has no head prints alone, on the left. Rows are separated by a rule in the frame's horizontal line; foot rows follow, in bold. - Decision 7's table needs 8 + 3 + 5 = 16 characters for its cells and 4 for its borders, so it stacks below 20: on a TM-T88 at size 3 (14 characters), not at size 2 (21).
- Trade-off: a stacked table looks unlike the table asked for, but no word of up to 8 characters is split.
- Limits. 1-8 columns; 1-100 rows; 0-10 foot rows; each row exactly as many cells as
cols;width0-255;grow0-10;padding0-3. A row with the wrong number of cells is a problem named by its index,rows[3]: 2 cells, want 3. Rows and cells do not count toward the 500-element limit, as kv pairs do not. The text a table holds is bounded bywebserver.body_limit(4 MiB) and its lines byformat.max_lines.- Today
max_linesis checked only once the whole job is laid out (render.go:148-151), so 500 tables each just under the limit, or one cell of 4 MiB in a narrow column, build about a million lines first. Stage 2 therefore first makes the renderer stop as soon as the lines so far, times the copies, passmax_lines, checked after each element, at each table row and inside a cell's wrap. The error then readsreceipt would print at least 2001 lines, limit is 2000, which changes the message api.md quotes (api.md:195-198), under Changed in the CHANGELOG. The code,too_many_lines, stays. - The tags:
colsminItems=1,maxItems=8;rowsminItems=1,maxItems=100;footmaxItems=10alone, since no foot is the default; inColumn,widthminimum=0,maximum=255,growminimum=0,maximum=10andalignenum=left,enum=center,enum=right. No tag can say that a row has as many cells ascols; validation holds that rule, and the field's doc comment states it. TestBoundTagsMatchValidation gains rows forColumn, and TestEnumTagsMatchValidation'senumTag(schema_test.go:16-29) takes the type, so thatColumn.Alignis held too. - Trade-off: a long order of more than 100 lines needs two tables; a job over the limit is told only a lower bound on its lines.
- Today
- A table inside a box. Allowed, one level, as kv and list are. It takes
cols,rows,foot,styleandpaddingthere;sizeandfontcome from the box, and the table spans the box's content width. A table narrower than that, all fixed orfit, is centred in it and padded with spaces to it, so every box line keeps its width. Afitbox measures the table at its natural width. A framed table inside a box draws its own frame inside the box's; api.md suggestsnonethere.- Trade-off: a framed table inside a frame is busy, and nothing stops it.
- The JSON field names.
cols,rows,foot, and in a columnhead,align,widthandgrow. Notcolumnsfor the column definitions: on every blockcolumnsis already the block's width in characters (job.go:170-173).- Trade-off:
colsbesidecolumns, andfoot(rows) beside a box'sfooter(text in its bottom border), can be misread.
- Trade-off:
For stage 3, the banner:
- What a banner is. Large text that spans the line, for a heading such as
ORDER 42:{"type": "banner", "text": "ORDER 42"}. Its fields aretext(required),style,size,align(defaultcenter),boldandfont. Three styles:band, the default: white on black. Each line is padded with spaces to the banner's columns, the text placed in it byalign, and printed reversed, so the band covers the whole line.plain: the large text alone.ruled: a line of▄above and of▀below, at size 1, full width;=where the page lacks them (cp1252).- Every banner line, the
ruledlines included, is sent centred (ESC a 1) with no margin spaces, so the printer centres it in its print area and the dots left over split evenly at both edges. They are fewer than one character at the line's size: 32 dots for 10 columns of size 4 on 512 dots. Aplainline is sent with theESC aof itsaligninstead. - The banner's columns come from the smaller of the line's dots and the profile's, so that a
printer.columnswider than the paper cannot make the printer wrap a band. - Trade-off: the band is narrower than the paper by up to one character less a dot, split between the edges. On the TM-T88's 512 dots in Font A that is 32 dots at sizes 4, 5 and 8, and 8 dots at the other sizes. With
printer.columnsnarrower than the paper, a banner centres on the paper while the other blocks centre within the narrower line.
- Its size.
sizeis 1-8, or 0 for automatic. Automatic picks the largest size from 4 down to 2 at which every paragraph of the text fits on one line: the line holdslineDots / (glyph × size)characters, asblockColumnscomputes (render.go:484-486). On a TM-T88 in Font A that is 10, 14 or 21 characters; on 58 mm paper 8, 10 or 16. Text too long at size 2 wraps at size 2. Width and height are always equal.- Trade-off: automatic never goes past size 4, since each line of size 8 is 192 dots, 27 mm, of paper.
- Where a banner may go. At the top level and, once stage 5 has shipped, in a group; never in a box. A box prints every line at its one size (render.go:456), so its borders could not join a banner's lines.
- Trade-off: a card that wants a big heading puts the banner above the box.
For stage 4, inline spans:
- The shape. A
textelement takesspansin place oftext: an array of runs, each withtext(required, may hold\n),bold,underline(0-2),invert, and at the top levelsize,widthandheight(1-8 each):{"type": "text", "align": "center", "spans": [ {"text": "Table 4 · "}, {"text": "2 guests", "bold": true}, {"text": " · "}, {"text": "ALLERGY", "invert": true, "size": 2}]}- With
spans, the element keepsfont,alignandnewline; its owntext,bold,underline,invert,size,widthandheightare refused, so a style is never set in two places."wrap": falseis refused too, since the printer's own wrapping and the position after it assume one character width (render.go:382-386, render.go:508-519). 1-100 spans; a span'stextmay not be empty. - The tags:
spansminItems=1,maxItems=100; inSpan,textrequired,minLength=1,underlineminimum=0,maximum=2, andsize,widthandheightminimum=0,maximum=8, 0 meaning the default. - Text today already continues a line with
"newline": falseand wraps across sizes (render.go:354-392, TestRenderInlineMixedSizesWraps). Spans add what that cannot do: a word that changes style part-way stays one word; a mixed line can be centred or right-aligned as one line, sinceESC atakes effect only at the start of a line (Investigation findings, ESC/POS); spans work inside a box, where"newline": falseis refused (job.go:295-297); and one element replaces several towards the 500-element limit. - Trade-off: a field that only
texttakes; the older types refuse it, as they refuseoptional(block.go:93-96).
- With
- Wrapping with mixed sizes. Wrap measures in dots. A character of a run of width multiplier
wtakesw × glyphdots; a line holdslineDotsdots, less the position already used, as today. Words are found across runs, so**8**.50is one word. Each run is normalised on its own, so a combining mark at the start of a run cannot compose with the run before it. The printer aligns characters of different heights on one line at their baseline (Investigation findings, ESC/POS).- For text of one size the new wrap gives exactly today's lines (layout.go:56-115), so the compat fixtures
wrap,inlineandtext-styleskeep their bytes. It keeps today's rules, each of which a test pins: a run of spaces fits whole or not at all, sowrap(" word", 2, 10)gives["", "word"]; a first word that does not fit a continued line leaves an empty first line; a word longer than the whole line moves to a fresh line before it splits at the edge; the last line keeps its trailing spaces, which"newline": falserelies on; and where a character is wider than the whole line, as withprinter.columnsof 1 at size 2, the first line is empty and each character takes a line, aswrap("ab", 0, 1)gives["", "a", "b"]. - A tab fills with spaces of its run's width up to the next multiple of 8 such characters from the line's start, at least one; for text of one size that is today's
expandTabsfromp.x / glyph(render.go:373). - Stage 4's first commit makes the change alone. Today's
wrapmoves into a_test.gofile as the reference that a property test compares with; a copy outside the tests, with no caller, would fail staticcheck. - Trade-off: none known.
- For text of one size the new wrap gives exactly today's lines (layout.go:56-115), so the compat fixtures
- Spans in other blocks. Spans only in
text, at the top level and as a text child of a box. kv values, list items, table cells and banners stay plain strings.- Trade-off: a bold word in a table cell must wait.
- Sizes inside a box. Inside a box, spans take
bold,underlineandinvertonly. A box lays out in cells of one size and prints each line at that size (render.go:456), and a taller span would leave the side borders short on its line.- Trade-off: no large word inside a card.
For stage 5, the group:
- What a group holds.
{"type": "group", "title": "Kitchen", "children": [...]}. Its children are at least one element of any top-level type butgroup,rawandcut. They have no limit of their own, as a box's children have none: children of a group and children of a box inside it count toward the 500-element limit.childrenis shared with a box, so a limit of a group's own could not go into its tag. A group cannot go inside a box. It prints its heading, then each child as if it stood at the top level.- Templates do not need it: Expr's
concatandflattenturn one value into several elements of a flat list (docs/plans/templates.md, decision 11). A group gives a heading and a shared font where one is wanted. rawis refused because the token scope is checked on top-level elements only (server/auth.go:135-150); stage 5 makes that check walk groups too, so the refusal does not rest on validation alone.cutis refused so that a group is never split by a cut.- Trade-off: no group inside a group.
- Templates do not need it: Expr's
- Keep-together. A group adds nothing beyond what every receipt has. A job renders to one stream and is sent on one connection (design.md:39-46), so no other job's lines can come between a group's lines, and a receipt has no pages to break across. A group refuses
cut(decision 22), so no cut falls inside one. The plan names keep-together only to record that it means nothing more on a receipt.- Trade-off: none known.
- Shared style. The group's
fontandsize(1-3) are the defaults for children that take them and do not set their own.font:text,box,rule,kv,list, and, once their stages have shipped,tableandbanner.size: the same, less the banner, whose0means automatic, and less atextthat setswidth,heightorspans, which carry their own sizes. Aqr's size is its module size, so it never takes the group's.- A child's own value wins, unlike a box, whose children may not set them (block.go:115-116).
- Trade-off: a group's size can make a child's block wider than it was written for, as any size does.
- The heading.
titleprints as a rule with the title set in on the left,── Kitchen ──────────, in the group's font and size.stylepicks the rule's line from the rule styles, andtitle_boldprints the title bold. No title, no heading.- Trade-off: one look for every heading.
- Paths in errors and warnings. A child is named by its path,
elements[2].children[1], and a box child inside itelements[2].children[1].children[0], in validation problems, render errors and preview warnings. Images inside a group are loaded before anything renders, as every image is (render.go:175-193), keyed by path.- Trade-off: none known.
Investigation findings
Checked against the code at 10b6c57, offline: CanEncode over each glyph in the four code pages, and the files cited read. Nothing was printed, and no config.toml was read.
GLYPHS BY CODE PAGE
Checked with escpos.CodePage.CanEncode (codepage.go:105-118), which counts a glyph only where it maps to a byte of 0x20 or above, other than DEL:
| Glyphs | cp437 | cp850, cp858 | cp1252 |
|---|---|---|---|
single ┌┐└┘─│├┤┬┴┼ |
all | all | none |
double ╔╗╚╝═║╠╣╦╩╬ |
all | all | none |
double-h ╒╕╘╛╞╡╤╧╪ |
all | none | none |
double-v ╓╖╙╜╟╢╥╨╫ |
all | none | none |
shades and blocks ░▒▓█▀▄▌▐■ |
all | all but ▌▐ |
none |
rule characters *~=#+_^· |
all | all | all |
∙ ≈ ≡ |
all | none | none |
¤ § × ¯ ¦ |
none | all | all |
• |
none | none | prints |
▪ ♦ ◆ ★ ● ○ ◦ |
none | none | none |
So the ╤╪╧ junctions print only on cp437; on cp850 and cp858 a double-h table falls back to double whole, and on cp1252 to ascii. cp850 and cp858 differ only at 0xD5 (ı and €).
THE CODE THE BLOCKS SHARE
- A block's width is the line in characters of its own size and font:
lineDots / (glyph × size)(render.go:484-486), wherelineDotsis the profile's dots orprinter.columns× the Font A width (render.go:168-173).columnsnarrows a block, which is then centred (blocklayout.go:46-64). - Blocks lay out in cells: after
normalize, one rune is one cell (cells.go:18-22, normalize.go:37-44), andwrapcounts runes (layout.go:48-115). A block prints every line at one size and font, changing only bold, underline and invert between runs (render.go:409-499). - Validation is structural and reports every problem (job.go:228-254). Children are checked one level deep, for a box only (job.go:262-274). The element count adds box children (job.go:232-243). Fields are checked per type by tables (block.go:52-113).
- Text, as opposed to blocks, tracks the print position in dots and wraps across elements of different sizes (render.go:354-392).
Rendervalidates, loads every image, then lays out the whole job before it returns a byte (render.go:91-107);max_linesis checked on the complete job (render.go:148-151). The preview renders the same way and reads the bytes back (preview.go:35-78).- Images, unknown-character counts and preview image labels are keyed by top-level index (render.go:134-143, render.go:178-193, preview.go:84-130). The token's raw scope is checked on top-level elements (server/auth.go:135-150).
- The
styleenum onElementlists the box and rule styles together (job.go:160-163). TestEnumTagsMatchValidation holds each enum to validation, a value being valid when one of the listed elements accepts it (schema_test.go:86-138); TestBoundTagsMatchValidation does the same for limits (schema_test.go:163).
ESC/POS
- Unverified, since Epson's reference refuses automated fetches:
ESC atakes effect only at the start of a line in standard mode, and characters of different heights on one line align at their baseline (GS !). The preview already models the first (interpret.go:220-224); it does not model the second, so only paper shows it. - Reverse printing (
GS B) covers spaces, so spaces padded to the line make a band. Whether two lines of a reversed banner touch or leave a white gap depends on the line spacing against the character height.
WHERE THE FINDINGS ARE UNSURE
ESC aat the start of a line only, and baseline alignment underGS !: not read in the reference. Stages 3 and 4 read them before their code.- Whether the lines of a reversed banner touch: stage 3's paper check settles it.
THE OTHER PLANS
- job-store.md's preview image (its phase 3a) draws box drawing and shading from the cell geometry, every other glyph from a bitmap font. The new junctions are box drawing and need nothing more. Banners and spans need drawing at a run's
WandH, whichescpos.Runalready carries (interpret.go:29-38). That phase's golden PNGs include each block that has shipped. - printers.md: each printer renders with its own profile, so a table can stack on a narrow printer and not on a wide one.
format.max_linesis global (printers.md, the keys that belong to each printer), so a table that stacks into more lines can fail on one printer of a multicast. - remote-printers.md, the decision on where rendering happens: main renders in full and the agent writes the bytes unchanged. Nothing here changes that.
SOURCES
- Epson's ESC/POS command reference, read in a browser: https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/, the pages for
ESC a,GS !andGS B.
Overview
Five blocks, each built alone when a need appears. Suggested order, when needs are equal:
- Rule character (stage 1): the smallest, a field on an existing block.
- Table (stage 2): the block the owner described in most detail, and the one an order or a status list needs. The largest stage.
- Banner (stage 3): small, and a candidate for the urgent card.
- Inline spans (stage 4): touches the text path that every receipt uses, so its refactor is proven alone first.
- Group (stage 5): a heading and a shared font over several elements, built when one is wanted. Templates do not need it (docs/plans/templates.md, decision 11).
What prints, on cp437 and a TM-T88 at size 1:
***************** TODAY ******************
╒══════════════════════════╤═════╤═══════╕
│ Item │ Qty │ Price │
╞══════════════════════════╪═════╪═══════╡
│ Flat white │ 2 │ 7.00 │
│ Almond croissant │ 1 │ 3.50 │
╞══════════════════════════╪═════╪═══════╡
│ Total │ 3 │ 10.50 │
╘══════════════════════════╧═════╧═══════╛
── Kitchen ───────────────────────────────
Prep for 18:00
The rule is {"type": "rule", "char": "*", "text": "TODAY"}, and the table is decision 7's example. Columns 2 and 3 are as wide as their widest cells, and the first takes the rest: 42 characters less 4 borders and 6 spaces of padding leave 32, of which Qty takes 3 and Price 5. The last two lines are a group's heading and its first child. A banner prints ORDER 42 at size 4 as one white-on-black band of 10 characters, and spans print styled words within one wrapped line, which a text preview shows as plain text.
The same table at size 3, 14 characters wide, stacks. Its first row and the separator after it:
Item .... Flat
white
Qty ........ 2
Price ... 7.00
══════════════
COMPATIBILITY
- Every existing element, field and response keeps its meaning. TestRenderCompat, TestPaperReceipts and the block goldens keep their bytes.
- New types and fields only.
/printstays strictly decoded, so an older daemon refuses a job that uses them, as it refuses any unknown field. - The
styleenum gainsnone,band,plainandruled; thetypeenum gainstable,bannerandgroup. - A job over
format.max_linesis refused with a message that gives a lower bound on its lines (decision 12).
INVARIANTS
- Nothing reaches the printer unless the whole receipt rendered. Every new block lays out inside
Renderer.render, beforeRenderreturns a byte. - Layout never fails on a valid job. Widths clamp, padding gives way, tables stack, banners wrap. The only render-time failures stay
max_linesand images. - Validation stays structural. No problem depends on the printer's width or code page.
- Jobs stay printer-neutral. Every width comes from the profile, or
printer.columns, at render time; nothing hard-codes 42 or 512. - Text stays text. Every new string is normalised and stripped of control characters before it is encoded, and no new field sends bytes as given.
- Layout never panics. The fuzz target FuzzBlocks (fuzz_test.go:18) covers each new block. Its width check, every line as wide as the first and no wider than the line at the block's size (fuzz_test.go:67-79), holds for a table, framed or stacked, as it stands. A banner checks its text lines against its chosen size and its
ruledlines against size 1. A text with spans checks that no line passeslineDotsin dots. A group checks each child as it would at the top level.
Architecture
FIELDS AND TYPES
- job.go:
TypeTable,TypeBannerandTypeGroup, in the type enum. New fields onElement:char,cols([]Column),rowsandfoot([][]string),spans([]Span).Childrenserves a box and a group. New typesColumn(head,align,width,grow) andSpan(text,bold,underline,invert,size,width,height), each with jsonschema tags and doc comments whose first paragraph is the schema description. - Each stage also rewrites the doc comments, the schema descriptions, of the existing names that list the blocks or speak of a box only. They are the type constants' comment,
Element,Type, and each field a new block shares.Text,AlignandSizechange for a banner.Stylechanges for a table, a banner and a group.Padding,FitandColumnschange for a table.Children,TitleandTitleBoldchange for a group, and so doElementsandMaxElements. - block.go: the
fieldstable (block.go:52-88) gains each new field;blockOnlygainschar,cols,rowsandfoot;ownFieldsmapsspanstotext;blockFieldsandchildFieldsgain the new types.checkFieldsrefuses only fields listed there (block.go:140), so a field left out would be ignored silently. The first stage to run adds a test that every json tag ofElementhas its entry in the table. - job.go: each new type joins the "not allowed inside a box" case (job.go:282) as it lands, so that a box child of that type is refused by name and not as an unknown type; a table moves out of it once it may go inside a box.
- tools/genopenapi: TestRequestSchemasAreStrict (generate_test.go:191) lists
ColumnandSpan, with their required fields. problemsandvalidatetake where an element stands (top level, in a box, in a group) instead ofinBox, so paths go two levels deep (stage 5).
TABLE LAYOUT
For a table of n columns, width W characters (blockWidth, blocklayout.go:59-64) and padding p:
- The room for cells is
R = W − (n + 1) − 2pnfor a frame, orR = W − (n − 1)(1 + 2p)fornone. - Each column wants
want = min(word, natural, width)and needsneed = min(want, 8), each at least 1, wherewordis its longest word,naturalits longest line andwidthits fixed width if set, the header included. pdrops, one step at a time, whileR < Σ wantandp > 0. IfR < Σ needatp = 0, the table stacks (decision 11).- Each column starts at
need. Round 1 brings fixed columns towidthand auto columns to their least width, their longest word; round 2 brings auto columns tonatural. A round that cannot be met in full shares the room left in proportion to what each column still wants, by largest remainder, ties to the left. - Room still left goes to the
growcolumns in proportion, or to the first auto column, unlessfitis set or every column is fixed; the table is then narrower thanWand centred. - Lines: the top border, the header and its separator, the body, the foot and its separator, the bottom border. Every line is exactly the table's width before centring, as box lines are (blocklayout.go:105-158). Borders, fills and padding are plain; header and foot cells are bold.
BANNER PRINTING
A banner is not a cell block: it prints its text lines at its size and its ruled lines at size 1, each sent with ESC a 1 (a plain line with its align's), reversed for band, with no margin spaces. Each line counts as one toward max_lines, as a line of large text does today.
SPANS
text with spans lays out runs: each run normalised, then wrapped by dots (decision 19), then printed with changeStyle (render.go:488-499) extended to size. The position in dots carries over to the next element as today.
GROUPS
printer.element prints a group's heading as a rule, then each child through printer.element with the group's defaults filled in. loadImages, the preview's placeholders and labels, the unknown-character counts and checkRaw walk group children by path.
Phases
Every commit below that changes behaviour carries its own tests, goldens, docs, regenerated docs/swagger.json where a type changes, and CHANGELOG entry, under Added unless its stage says otherwise. Each stage's paper receipt is pinned as decision 2 says.
Stage 1: The rule character
Goal. rule takes char, one character repeated across the line, with its fold and then its style as the fallback. Decisions 1-6.
Work.
- block.go:
charin the fields tables, onruleat the top level only;ruleSpecchecks it (decision 4). - glyphs.go: the pattern for a rule with
char(decision 5). - blocklayout.go:
ruleuses it (blocklayout.go:362-366). - job.go:
CharwithminLength=1,maxLength=1. - examples/rule-char.json:
*,~,=,■,•(folding to·),♦(falling back to the style), each with a label, and one atsize: 2. - docs/api.md §
ruleand § Glyphs and code pages; design.md, the decision.
Tests.
- testdata/blocks/rule-char.json, goldens in the three code pages.
- Validation: two runes, a combining mark, a format character, a control character,
\n,charinside a box, each refused with its message; a space accepted;""as unset. - The fallback order on every code page, U+212B composed first, cp858 equal to cp850.
- TestBoundTagsMatchValidation covers
char's upper bound alone. FuzzBlocks setschar. - If no other stage has run: the test that every json tag of
Elementis in thefieldstable. - A golden PNG of examples/rule-char.json, if job-store phase 3a has shipped.
Commits.
- Add a custom character to the rule block
Done when.
- The full gate passes.
- Paper, with the owner's OK: examples/rule-char.json. Look at each character, the label's place and spacing, the line's ends at both edges, and the size-2 rule. Wait for his report, then pin the bytes.
Stage 2: The table
Goal. A table block with columns, rows, a header and foot rows, in every box style and none, sized by content to the paper, wrapping in cells and stacking when its columns do not fit. It may go inside a box. Decisions 1-3 and 7-14.
Work.
- render.go: the
printerknowsMaxLinesand the copies, and stops as soon as the lines so far, times the copies, pass the limit (decision 12);LineLimitErrorsays "at least" when it stopped early. docs/api.md'stoo_many_linesexample (api.md:195-198); CHANGELOG under Changed. - job.go:
TypeTable,Column,Cols,Rows,Foot; thestyleenum gainsnone. - block.go:
tableSpec, with the checks of decision 12, and the problems of each row by index. - glyphs.go: the table's border sets, junctions included, with the fallback of decision 1;
none. - blocklayout.go (or a new tablelayout.go): TABLE LAYOUT; the stacked form through
kvLines; a table item in a box, with its natural width forfit. - render.go:
tableinprinter.elementandprinter.block; the table's layout and its cells' wrap check the line limit at each row. - Two receipts: examples/table.json, decision 7's table in
double-h,singleandnone; examples/table-narrow.json, a narrow one bycolumnsthat wraps cells, one that stacks, and anonetable in a box. - docs/api.md: §
tablewith examples and the field table, the Elements intro (api.md:307-308), the Blocks intro (api.md:409-419), § Glyphs and code pages, and §box's children (api.md:463-475) for commit 4; README's list of blocks (README.md:11); design.md, the decisions.
Tests.
- testdata/blocks/table-styles.json, table-widths.json (fixed, auto,
grow,fit, all fixed), table-wrap.json, table-narrow.json (padding given up, words split, stacked) and table-box.json, goldens in the three code pages. - Width sums: every line of every golden table is exactly the table's width; a table test on the tm-t20 and generic-58mm profiles, so widths follow the profile.
- Distribution: largest remainder and ties to the left, by table test.
- Validation: each limit of decision 12, a ragged row,
growwithwidth, an unknownalign, each refused with its path. - The early stop: 500 text elements of 10 lines each against a limit of 100 stop at the eleventh element, by a count of elements rendered; a table of 100 rows in a 1-character column stops at the row that passes the limit, by
testing.AllocsPerRunagainst a table that fits. Under the limit, every compat fixture keeps its bytes. - cp858 equal to cp850; schema tag tests; FuzzBlocks with tables.
- Golden PNGs of the two examples, if job-store phase 3a has shipped.
Commits.
- Stop rendering a receipt once it passes max_lines
- Add the table block
- Add foot rows to the table block
- Allow a table inside a box
Commit 2 includes the stacked form: without it, a framed table on a line narrower than 2n + 1 characters would print lines wider than the block. The examples and goldens grow with the commits, since TestExampleJobs checks every example at each one. Commit 2 has decision 7's table without its foot, in double-h, single and none, the narrow one that wraps and the one that stacks. Commit 3 adds the foot, which the stacked form prints too. Commit 4 adds the none table in a box, with testdata/blocks/table-box.json. If commit 2 passes the 800-line split point, "Add a frameless style to the table block" comes out of it, after it.
Done when.
- The full gate passes.
- Paper, with the owner's OK, one receipt at a time: examples/table.json, then examples/table-narrow.json. Look at the
╤╪╧junctions meeting the vertical lines (the gaps the box borders show are expected), columns lining up, right-aligned numbers, wrapped cells, the bold header and foot, and the stacked form. Wait for his report on each, then pin the bytes.
Stage 3: The banner
Goal. A banner block of large text across the line in band, plain or ruled, sized automatically from the paper. Decisions 1-3 and 15-17.
Work.
- Before the code: read
ESC aandGS Bin Epson's command reference, in a browser. If a finding under ESC/POS does not hold, stop and ask the owner. - job.go:
TypeBanner; thestyleenum gainsband,plainandruled. - block.go:
bannerSpec:textrequired,size0-8,style,align,bold,font. - render.go and blocklayout.go: the automatic size (decision 16), the lines, BANNER PRINTING.
- Two receipts: examples/banner.json,
ORDER 42in each style at the automatic size and in Font B; examples/banner-large.json, a two-line band and size 8. - docs/api.md: §
banner, the Elements intro, the Blocks intro (a banner takessize0-8 and nocolumns), § Glyphs and code pages (▄ ▀as=on cp1252); README's list of blocks; design.md, the decisions.
Tests.
- testdata/blocks/banner.json, goldens in the three code pages.
- The automatic size on tm-t88, tm-t20 and generic-58mm, and with
printer.columnsset. - The bytes:
ESC a 1, the size, reverse on and off, no margin spaces, byTestRenderBlocksBytes's pattern (blocks_test.go:367). - Validation; a banner inside a box refused; cp858 equal to cp850 for the
ruledlines; schema tag tests; FuzzBlocks with banners. - Golden PNGs of the two examples, if job-store phase 3a has shipped.
Commits.
- Add the banner block
Done when.
- The full gate passes.
- Paper, with the owner's OK, one receipt at a time: examples/banner.json, then examples/banner-large.json. Look at the band's edges and the even white margin on each side, the text centred in the band, whether two lines of a band touch, the
ruledlines, and size 8. Wait for his report on each, then pin the bytes.
Stage 4: Inline spans
Goal. text takes spans: styled runs within one line or wrapped paragraph, at the top level and in a box. Decisions 2, 3 and 18-21.
Work.
- Before the code: read
ESC aandGS !in Epson's command reference, in a browser. If a finding under ESC/POS does not hold, stop and ask the owner. - layout.go: wrap measures each character's width (decision 19), with today's
wrapits case of equal widths. This commit changes no byte. - job.go:
SpanandSpans. - block.go and job.go: the checks of decision 18, and decision 21's inside a box;
ownFieldsgainsspans. - render.go:
textwith spans: normalise each run, wrap by dots, print runs with style and size changes, reset the style after. - blocklayout.go: a text child with spans lays out as styled runs in cells.
- examples/spans.json: decision 18's line; a paragraph that wraps across bold, underlined, inverted and size-2 runs; a word that changes style part-way; and, from commit 3, spans in a box.
- docs/api.md §
textand §box; design.md, the decisions.
Tests.
- The new wrap equals today's for every case of layout_test.go and for random text of one size (a property test). TestRenderCompat passes unchanged.
- Mixed sizes break where the dots run out, not the characters; a word across runs stays whole; a character wider than the line takes its own line.
- testdata/blocks/spans.json, goldens in the three code pages; the preview's runs carry each span's style and size.
- Validation:
textwithspans, an element style with spans,"wrap": falsewith spans, an empty span, a spansizeinside a box, 101 spans, each refused;spanson aqrrefused. - Tabs in runs of different widths stop where decision 19 says.
- Schema tag tests; FuzzBlocks with spans.
- A golden PNG of examples/spans.json, if job-store phase 3a has shipped.
Commits.
- Wrap text by the width of each character
- Add inline spans to the text element
- Allow spans in text inside a box
Commit 1 changes no behaviour, so it has no docs or CHANGELOG entry. Commit 2's examples/spans.json has no box; commit 3 adds the spans in a box.
Done when.
- The full gate passes.
- Paper, with the owner's OK: examples/spans.json. Look at the baseline of mixed sizes, where lines break, styles starting and stopping at the right letter, the centred line, and the box borders beside styled runs. Wait for his report, then pin the bytes.
Stage 5: The group
Goal. A group holds elements under an optional heading, with a shared font and size. Decisions 2, 3 and 22-26.
Work.
- job.go and block.go: validation by where an element stands (Architecture, FIELDS AND TYPES), with no change to what a box accepts or to any message. This commit changes no behaviour.
- job.go:
TypeGroup; the element count adds group children and the box children inside them. - block.go:
groupSpec:children,title,title_bold,style(a rule style),sizeandfont. - render.go and preview.go: GROUPS, images and warnings by path.
- server/auth.go:
checkRawwalks every child list, a box's and a group's, by path. - examples/group.json: a heading, a box and a kv inside, Font B shared, a child with its own size, and a table if stage 2 has shipped.
- docs/api.md: §
group, the Elements intro, the Blocks intro, §box(a group cannot go inside one), the 500-element limit counting group children; README's list of blocks; design.md, the decisions.
Tests.
- The validation refactor: every existing validation test passes unchanged.
- Paths in problems, render errors and preview warnings; an image inside a group loads, previews with its label, and an optional one that fails prints
[image unavailable]. - The element count across groups and boxes; a group in a group,
raw,cutand a group in a box, each refused. checkRawnames a raw element inside a group, built without validation, aselements[0].children[1] (raw).- The shared font and size, and a child's own value winning; a
qrkeeps its size. - testdata/blocks/group.json, goldens in the three code pages; schema tag tests; FuzzBlocks with groups.
- A golden PNG of examples/group.json, if job-store phase 3a has shipped.
Commits.
- Validate elements by where they stand in the job
- Add the group block
Commit 1 changes no behaviour, so it has no docs or CHANGELOG entry.
Done when.
- The full gate passes.
- Paper, with the owner's OK: examples/group.json. Look at the heading, the children's spacing and the shared font. Wait for his report, then pin the bytes.