Add a note text size option; document the printer cabled to stppi
- 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:
+14
-4
@@ -36,6 +36,7 @@ CSRF_HEADER_VALUE = "receipt"
|
||||
class Note(BaseModel):
|
||||
text: str = Field(min_length=1, max_length=MAX_NOTE_CHARS)
|
||||
timestamp: bool = False
|
||||
size: int = Field(default=1, ge=min(receipt.TEXT_SIZES), le=max(receipt.TEXT_SIZES))
|
||||
|
||||
|
||||
def create_app(base: argparse.Namespace, token: str) -> FastAPI:
|
||||
@@ -78,7 +79,7 @@ def create_app(base: argparse.Namespace, token: str) -> FastAPI:
|
||||
def note(body: Note) -> JSONResponse:
|
||||
if not body.text.strip():
|
||||
raise HTTPException(400, "Nothing to print.")
|
||||
return run("note", text=body.text, timestamp=body.timestamp)
|
||||
return run("note", text=body.text, timestamp=body.timestamp, size=body.size)
|
||||
|
||||
@app.post("/api/image", dependencies=posting)
|
||||
def image(
|
||||
@@ -152,10 +153,11 @@ PAGE = """<!doctype html>
|
||||
section {
|
||||
background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
|
||||
}
|
||||
textarea, input[type=text] {
|
||||
textarea, input[type=text], select {
|
||||
width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
|
||||
background: var(--bg); color: var(--text); font: inherit;
|
||||
}
|
||||
select { width: auto; padding: 4px 6px; margin-left: 4px; }
|
||||
textarea { min-height: 140px; font-family: ui-monospace, monospace; resize: vertical; }
|
||||
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
||||
margin-top: 10px; flex-wrap: wrap; }
|
||||
@@ -195,9 +197,16 @@ PAGE = """<!doctype html>
|
||||
<section>
|
||||
<h2>Note</h2>
|
||||
<form id="note-form">
|
||||
<textarea id="note" maxlength="4000" placeholder="Wrapped to 48 columns" required></textarea>
|
||||
<textarea id="note" maxlength="4000" placeholder="Your note" required></textarea>
|
||||
<div class="row">
|
||||
<label class="muted"><input type="checkbox" id="timestamp"> Date/time header</label>
|
||||
<label class="muted">Size
|
||||
<select id="size">
|
||||
<option value="1">Normal (48 per line)</option>
|
||||
<option value="2" selected>Large (24 per line)</option>
|
||||
<option value="3">Huge (16 per line)</option>
|
||||
</select>
|
||||
</label>
|
||||
<button type="submit">Print note</button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -275,7 +284,8 @@ $("note-form").addEventListener("submit", async (e) => {
|
||||
const ok = await submit(e.target, "api/note", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({text: $("note").value, timestamp: $("timestamp").checked}),
|
||||
body: JSON.stringify({text: $("note").value, timestamp: $("timestamp").checked,
|
||||
size: Number($("size").value)}),
|
||||
});
|
||||
if (ok) $("note").value = "";
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user