Add a note text size option; document the printer cabled to stppi
CI / test (3.10) (push) Failing after 47s
CI / test (3.12) (push) Failing after 54s
CI / test (3.13) (push) Failing after 48s

- 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]>
This commit is contained in:
2026-10-23 21:48:54 +01:00
co-authored by Claude Opus 5.5
parent f55b20fb82
commit 30d1b83817
7 changed files with 70 additions and 14 deletions
+3
View File
@@ -18,6 +18,9 @@ class FakePrinter:
def qr(self, content, **kwargs):
self.calls.append(("qr", content))
def set(self, **kwargs):
self.calls.append(("set", kwargs))
def cut(self):
self.calls.append(("cut", None))
+14 -1
View File
@@ -134,6 +134,16 @@ def test_cmd_note_wraps_and_cuts():
assert p.calls[-1] == ("cut", None)
def test_cmd_note_large_size_wraps_narrower_and_resets():
p = FakePrinter()
rc = receipt.cmd_note(p, make_args(text="hello " * 20, size=2))
assert rc == 0
assert p.calls[0] == ("set", {"custom_size": True, "width": 2, "height": 2})
assert all(len(line) <= receipt.TEXT_COLUMNS // 2 for line in p.calls[1][1].split("\n"))
assert p.calls[2:] == [("set", {"normal_textsize": True}), ("cut", None)]
def test_cmd_note_timestamp_header():
p = FakePrinter()
rc = receipt.cmd_note(p, make_args(text="hi", timestamp=True))
@@ -214,7 +224,10 @@ def test_parser_handles_all_subcommands():
assert args.usb and args.text == "hello" and args.timestamp
args = parser.parse_args(["note"])
assert args.text is None # stdin mode
assert args.text is None and args.size == 1 # stdin mode
args = parser.parse_args(["note", "big", "--size", "3"])
assert args.size == 3
args = parser.parse_args(["--ip", "10.0.0.5", "--port", "9101", "status"])
assert args.ip == "10.0.0.5" and args.port == 9101
+15
View File
@@ -76,6 +76,21 @@ def test_note_prints(client, fake_printer):
assert fake_printer.calls[-2:] == [("cut", None), ("close", None)]
def test_note_size(client, fake_printer):
res = client.post("/api/note", headers=HEADERS, json={"text": "hello", "size": 3})
assert res.status_code == 200
assert ("set", {"custom_size": True, "width": 3, "height": 3}) in fake_printer.calls
@pytest.mark.parametrize("size", [0, 4])
def test_note_rejects_bad_size(client, fake_printer, size):
res = client.post("/api/note", headers=HEADERS, json={"text": "hi", "size": size})
assert res.status_code == 422
assert fake_printer.calls == []
@pytest.mark.parametrize("text", ["", " ", "x" * (receipt_web.MAX_NOTE_CHARS + 1)])
def test_note_rejects_empty_and_long(client, fake_printer, text):
res = client.post("/api/note", headers=HEADERS, json={"text": text})