Skip to content

Add configurable printer width#79

Open
Igglybuff wants to merge 3 commits into
eljojo:mainfrom
Igglybuff:feature/configurable-width
Open

Add configurable printer width#79
Igglybuff wants to merge 3 commits into
eljojo:mainfrom
Igglybuff:feature/configurable-width

Conversation

@Igglybuff
Copy link
Copy Markdown

Adds a PRINTER_WIDTH environment variable (default 576, matching the existing 80mm TSP650II behaviour) so the service works correctly with narrower printers like the 58mm mC-Print2 (384 dots).

The width is used to calculate chars_per_line for word wrapping and the divider width in the receipt handler. Previously these were hardcoded or calculated from a fixed width, which produced incorrect output on narrower paper.

Also fixes a build error: adds the missing env feature to the clap dependency.

🤖 Generated with Claude Code

Igglybuff and others added 3 commits May 23, 2026 10:33
The serve command gains a --width flag (also readable from the
PRINTER_WIDTH env var) specifying the printer's dot width. Defaults to
576 to match the TSP650II. Set to 384 for 58mm printers like the
Star mC-Print2.

All server handlers (photo, patterns, weave, receipt) now derive the
print width from the configured value instead of a hardcoded reference
to PrinterConfig::TSP650II. Dividers in the patterns and weave handlers
derive their character width from the printer dot width so they don't
wrap on narrower paper.

Adds PrinterConfig::MCP21 (384 dots, 58mm) alongside the existing
TSP650II constant, and a PrinterConfig::with_width() constructor for
building a config from an arbitrary dot width.

PRINTER_DEVICE and LISTEN_ADDR env vars are also added to the other
serve options for consistency.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Same fix as patterns and weave: derive chars_per_line from printer_width
instead of using Divider::default(), which assumed TSP650II column count.
Also threads printer_width into the preview handler.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The env attribute on #[arg] requires clap's env feature flag.
The PrinterConfig import in receipt.rs was unused after refactoring
build_receipt to take a raw u16 width.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Igglybuff
Copy link
Copy Markdown
Author

I suppose since the Star print protocol should be pretty universal for these printers, the main (only?) thing preventing this project from supporting any old Star Micronics printer is the paper width? You just need to provide the right parameters for your printer and it should just work. What you probably don't want is a bunch of model-specific code everywhere, but then you put more responsibility on the user to configure estrella correctly for their model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant