Closed cervantes-x closed 2 months ago
Since version 3, when attempting to reset the width value to 1 and create a table afterwards, the table continues to use the previously set width value. However, if some text is created before the table, the width resets correctly.
const encoder = new ReceiptPrinterEncoder({ columns: 48, printerModel: "pos-5890", }); const result = encoder .initialize() .codepage("windows1252") .align("center"); const firstColumnWidth = Math.round(width * 0.1); const secondColumnWidth = Math.round(width * 0.5); result.width(2).line("-".repeat(width / 2)); // Attempt to reset width to 1 (this does NOT work) result.width(1); result.table( [ { width: firstColumnWidth, marginRight: 1, align: "right" }, { width: secondColumnWidth, align: "left" }, { width: width - firstColumnWidth - secondColumnWidth - 1, align: "right", }, ], [ ["1x", "Spaghetti Bolognese", "€ 10,00"], ["10x", "Spagetti alla carbonara", "€ 100,00"], ], ); const encoded = result.encode(); sendToPrinter(encoded, printer); });
const encoder = new ReceiptPrinterEncoder({ columns: 48, printerModel: "pos-5890", }); const result = encoder .initialize() .codepage("windows1252") .align("center"); const firstColumnWidth = Math.round(width * 0.1); const secondColumnWidth = Math.round(width * 0.5); result.width(2).line("-".repeat(width / 2)); // Reset width to 1 and create some text (this works) result.width(1); result.text(""); result.table( [ { width: firstColumnWidth, marginRight: 1, align: "right" }, { width: secondColumnWidth, align: "left" }, { width: width - firstColumnWidth - secondColumnWidth - 1, align: "right", }, ], [ ["1x", "Spaghetti Bolognese", "€ 10,00"], ["10x", "Spagetti alla carbonara", "€ 100,00"], ], ); const encoded = result.encode(); sendToPrinter(encoded, printer); });
The width value should be set to 1 and applied to the table even when no text is created beforehand.
The width is not reset when directly creating the table after setting width(1). It only resets correctly if some text is created before the table.
Should be fixed in release 3.0.1
Since version 3, when attempting to reset the width value to 1 and create a table afterwards, the table continues to use the previously set width value. However, if some text is created before the table, the width resets correctly.
Code example (Not working):
Code example (Working):
Expected Behavior:
The width value should be set to 1 and applied to the table even when no text is created beforehand.
Actual Behavior:
The width is not reset when directly creating the table after setting width(1). It only resets correctly if some text is created before the table.