Skip to content

Commit 655753f

Browse files
authored
Merge pull request #101 from da-Kai/main
Add barcode to cli --batch
2 parents 25b1149 + 288b74f commit 655753f

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,16 @@ commands are:
206206
* `NEWLINE`: Adds an additional line to the current block of text or QR. Used to
207207
create multiline blocks.
208208
* `QR`: Creates a QR code block
209+
* `BARCODE`: Creates a barcode block. Optional: Can be preceded by #`TYPE`,
210+
to generate a different barcode; default is CODE128, . e.g. `BARCODE#EAN:123456789012`
209211

210212
For instance, this input:
211213

212214
```text
213215
LABELLE-LABEL-SPEC-VERSION:1
214216
TEXT:FD12
215217
NEWLINE:2013
216-
QR:1234
218+
BARCODE:1234
217219
TEXT:BIG
218220
TEXT:LINE1
219221
NEWLINE:LINE2
@@ -223,7 +225,7 @@ QR:12345
223225
Creates a label with:
224226

225227
* A 2-line text block (first line `FD12`, second line `2013`)
226-
* Then, a QR code for 1234
228+
* Then, a barcode code for 1234
227229
* Then, a line-line text block with the text `BIG`
228230
* Then, another 2-line text block
229231
* Finally, a QR code

doc/batch-example.png

113 Bytes
Loading

src/labelle/cli/cli.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,22 +507,34 @@ def render_text(lines):
507507
if batch:
508508
accumulator: List[str] = []
509509
accumulator_type: str = "empty"
510+
accumulator_options: List[str] = []
510511

511512
def flush_all():
512513
nonlocal accumulator
513514
nonlocal accumulator_type
515+
nonlocal accumulator_options
514516
if accumulator_type == "text":
515517
render_text(accumulator)
516518
elif accumulator_type == "qr":
517519
render_engines.append(
518520
QrRenderEngine(qr_callback("\n".join(accumulator)))
519521
)
522+
elif accumulator_type == "barcode":
523+
barcode_type = (
524+
BarcodeType(accumulator_options[0].lower())
525+
if accumulator_options
526+
else DEFAULT_BARCODE_TYPE
527+
)
528+
render_engines.append(
529+
BarcodeRenderEngine("\n".join(accumulator), barcode_type)
530+
)
520531

521532
accumulator = []
522533
accumulator_type = "empty"
534+
accumulator_options = []
523535

524536
# Verify version
525-
line = sys.stdin.readline().strip()
537+
line: str = sys.stdin.readline().strip()
526538
parts = line.split(":", 1)
527539
if not (parts[0] == "LABELLE-LABEL-SPEC-VERSION" and parts[1] == "1"):
528540
err_console = Console(stderr=True)
@@ -533,17 +545,24 @@ def flush_all():
533545

534546
for line in sys.stdin:
535547
line = line.rstrip("\r\n")
536-
parts = line.split(":", 1)
537-
if parts[0] == "TEXT":
548+
settings, value = line.split(":", 1)
549+
setting, *options = settings.split("#", 1)
550+
551+
if setting == "TEXT":
538552
flush_all()
539553
accumulator_type = "text"
540-
accumulator.append(parts[1])
541-
elif parts[0] == "QR":
554+
accumulator.append(value)
555+
elif setting == "QR":
542556
flush_all()
543557
accumulator_type = "qr"
544-
accumulator.append(parts[1])
545-
elif parts[0] == "NEWLINE":
546-
accumulator.append(parts[1])
558+
accumulator.append(value)
559+
elif setting == "BARCODE":
560+
flush_all()
561+
accumulator_type = "barcode"
562+
accumulator_options = options
563+
accumulator.append(value)
564+
elif setting == "NEWLINE":
565+
accumulator.append(value)
547566
else:
548567
print("WARNING: invalid command", line)
549568
flush_all()

0 commit comments

Comments
 (0)