Skip to content

Commit 88f00e7

Browse files
committed
Make sure we do not auto-flush after a cut or pulse command, as it already flushed itself and causes an extra newline to be printed
1 parent 33546a9 commit 88f00e7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/receipt-printer-encoder.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,9 +1228,23 @@ class ReceiptPrinterEncoder {
12281228
* @return {array} All the commands currently in the queue
12291229
*/
12301230
commands() {
1231+
let requiresFlush = true;
1232+
1233+
/* Determine if the last command is a pulse or cut, the we do not need a flush */
1234+
1235+
let lastLine = this.#queue[this.#queue.length - 1];
1236+
1237+
if (lastLine) {
1238+
let lastCommand = lastLine[lastLine.length - 1];
1239+
1240+
if (lastCommand && [ 'pulse', 'cut' ].includes(lastCommand.type)) {
1241+
requiresFlush = false;
1242+
}
1243+
}
1244+
12311245
/* Flush the printer line buffer if needed */
12321246

1233-
if (this.#options.autoFlush && !this.#options.embedded) {
1247+
if (requiresFlush && this.#options.autoFlush && !this.#options.embedded) {
12341248
this.#composer.add(
12351249
this.#language.flush(),
12361250
);

0 commit comments

Comments
 (0)