diff --git a/app.rb b/app.rb index e9ab491..05aeb1e 100644 --- a/app.rb +++ b/app.rb @@ -132,8 +132,9 @@ helpers do def print_epson_test_page receipt = ReceiptBuilder.new receipt.align(:center).bold.size(:big).text("TM-T20II TEST\n").size(:normal).bold(false) + receipt.align(:left).text(('-' * 48) + "\n") - receipt.align(:left).section_separator('TEXT STYLES') + receipt.section_separator('TEXT STYLES') receipt.text("Normal text\n") receipt.bold.text("Bold text\n").bold(false) receipt.underline.text("Underlined text\n").underline(false) @@ -150,8 +151,8 @@ helpers do receipt.section_separator('IMAGE') receipt.align(:center).image(64, 64, checkerboard_bitmap) - receipt.section_separator - receipt.align(:left).text("Printed: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}\n") + receipt.align(:left).text(('-' * 48) + "\n") + receipt.text("Printed: #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}\n") receipt.feed(3).cut receipt.print!(PRINTER_DEVICE_EPSON) end diff --git a/lib/receipt_builder.rb b/lib/receipt_builder.rb index f7cc890..62d302b 100644 --- a/lib/receipt_builder.rb +++ b/lib/receipt_builder.rb @@ -65,17 +65,26 @@ class ReceiptBuilder self end - # White-on-black reverse video (GS B n) -- the closest this direct-thermal - # printer gets to a second "color" for a separator/banner. + # White-on-black reverse video (GS B n) -- available if a receipt ever + # wants a real highlight, but plain "=" rules read better for routine + # section breaks than a fully blacked-out line. def invert(enable = true) @buffer << (enable ? "\x1D\x42\x01" : "\x1D\x42\x00") self end - # A full-width inverted banner line, e.g. section_separator("SECTION"). + # A single "=" rule with an optional label centered in it, e.g. + # section_separator("SECTION") -> "========= SECTION =========". def section_separator(label = '', width: 48) - padded = label.empty? ? (' ' * width) : " #{label} ".center(width) - feed(1).invert.text(padded[0, width]).invert(false).feed(1) + line = if label.empty? + '=' * width + else + mid = " #{label} " + pad = [width - mid.length, 0].max + left = pad / 2 + ('=' * left) + mid + ('=' * (pad - left)) + end + feed(1).text("#{line}\n").feed(1) end def size(mode)