- note --size 1|2|3 magnifies the text and wraps to 48/24/16 columns, then resets the printer to normal size - Web page gets a Size menu defaulting to Large; the API validates it - README/CLAUDE.md: the printer has no Wi-Fi (UB-E04 needs an adapter), so it is cabled to stppi's eth0 at 192.168.192.168 Co-Authored-By: Claude Opus 5.5 <[email protected]>
2.5 KiB
2.5 KiB
Receipt Maker
CLI that prints images, notes, and QR codes to an Epson TM-T20II thermal receipt printer (Ethernet via USB adapter, or direct USB with --usb).
Layout
receipt.py— the CLI; subcommand percmd_*functionreceipt_tui.py— Textual TUI (tuisubcommand); thin layer over thecmd_*handlers viareceipt.run_action(), which connects fresh per action and captures stdout/stderr for the log panel.textualis an optional dependency ([tui]extra); the CLI works without itreceipt_web.py— FastAPI server (servesubcommand,[web]extra) behind the site's nginx/receipt/over Tailscale; requires theX-Receipt-Tokenheader nginx adds, andX-Requested-With: receipton POSTs. Serializes jobs with a lock aroundrun_action(); uploads print from memory. Always runs withno_setup(no sudo; the printer must already be reachable). Deployed on stppi, which is online over Wi-Fi and has the printer cabled to itseth0(printer 192.168.192.168, Pi 192.168.192.10 via thereceipt-printernmcli profile)deploy/— systemd user units;update.sh(run byreceipt-update.timer) fast-forwards the server's clone from Gitea, runs the tests, and restartsreceipt-web, rolling back if they fail. Pushing to Giteamasteris the deployconnect_receipt.sh— brings up the printer's network interface (needs sudo); run automatically before any print over Ethernet. The TUI runs it with output captured (setup_network_quiet) so it can't corrupt the screentests/— pytest suite; usesFakePrinter+ mockedrequests, never touches hardware or network
Conventions
- Printer/network constants live at the top of
receipt.py; IP/port overridable via--ip/--portorRECEIPT_PRINTER_IP/RECEIPT_PRINTER_PORT - Images are prepared in memory (
prepare_for_print: white-composite alpha → resize to 576px → autocontrast → 1-bit dither); nothing is written except theimg/download cache print_image()reconnects and retries once on failure and returns the (possibly new) printer handle — callers must rebindp- Commands that don't need the printer (
list,clean) or handle their own connection (status,tui,serve) are dispatched inmain()before connecting --no-setup(args.no_setup) skips the connect script everywhere it would run; check it withneeds_setup(args)
Checks
pytest # required
ruff check . # lint (config in pyproject.toml)
Actual printing can only be verified with the physical printer attached.