@@ -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