Skip to content

Commit

Permalink
printChefDishs support \n
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinzhang-microsoft committed May 2, 2023
1 parent a4722a9 commit 89ed4bd
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 51 deletions.
3 changes: 3 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 5.7.0
- support '\n' in chef menu

# 5.6.0
- support oneline() and line() break line if encounter with '\n'
30 changes: 20 additions & 10 deletions dist/esc-pos-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,20 +343,30 @@ var EscPosEncoder = /** @class */ (function () {
_this.line((dish.count > 1 ? dish.count + "x " : '') + dish.name);
}
else {
var fixedWidthStrArr = _this.splitByWidth(dish.name, _this.singleCharLengthPerLine - countAndPriceLength);
fixedWidthStrArr.forEach(function (str, index) {
if (index === 0) {
_this.oneLine(str, "x" + dish.count);
}
else {
_this.line(str);
}
});
var nameArr = dish.name.split('\n');
var _loop_2 = function (i) {
var name_2 = nameArr[i];
var fixedWidthStrArr = _this.splitByWidth(name_2, _this.singleCharLengthPerLine - countAndPriceLength);
fixedWidthStrArr.forEach(function (str, index) {
if (i === 0 && index === 0) {
_this.oneLine(str, "x" + dish.count);
}
else {
_this.line(str);
}
});
};
for (var i = 0; i < nameArr.length; i++) {
_loop_2(i);
}
}
if (specificationInNewLine) {
(_a = dish.specifications) === null || _a === void 0 ? void 0 : _a.forEach(function (str, index) {
if (str) {
_this.line(' * ' + str + ' *');
var strArr = str.split('\n');
strArr.forEach(function (specString) {
_this.line(' * ' + specString + ' *');
});
}
});
}
Expand Down
36 changes: 23 additions & 13 deletions dist/esc-pos-img-encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,23 +558,33 @@ var EscPosImgEncoder = /** @class */ (function (_super) {
_this.line((dish.count > 1 ? dish.count + "x " : '') + dish.name);
}
else {
var fixedWidthStrArr = _this.splitByWidth(dish.name, _this.CVS.width - countAndPriceLength);
fixedWidthStrArr.forEach(function (str, index) {
if (dish.count <= 0) {
return;
}
if (index === 0) {
_this.oneLine(str, "x" + dish.count);
}
else {
_this.line(str);
}
});
var nameArr = dish.name.split('\n');
var _loop_2 = function (i) {
var name_2 = nameArr[i];
var fixedWidthStrArr = _this.splitByWidth(name_2, _this.CVS.width - countAndPriceLength);
fixedWidthStrArr.forEach(function (str, index) {
if (dish.count <= 0) {
return;
}
if (i === 0 && index === 0) {
_this.oneLine(str, "x" + dish.count);
}
else {
_this.line(str);
}
});
};
for (var i = 0; i < nameArr.length; i++) {
_loop_2(i);
}
}
if (specificationInNewLine) {
(_a = dish.specifications) === null || _a === void 0 ? void 0 : _a.forEach(function (str, index) {
if (str) {
_this.line(' ※ ' + str + ' ※');
var strArr = str.split('\n');
strArr.forEach(function (specString) {
_this.line(' ※ ' + specString + ' ※ ');
});
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@freedom_sky/esc-pos-encoder",
"version": "5.6.0",
"version": "5.7.0",
"description": "Create a set of commands that can be send to any receipt printer that supports ESC/POS",
"main": "dist/esc-pos-encoder.js",
"types": "dist/esc-pos-encoder.d.ts",
Expand Down
31 changes: 19 additions & 12 deletions src/esc-pos-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,29 @@ export default class EscPosEncoder {
if (countFront) {
this.line((dish.count>1?`${dish.count}x `:'')+dish.name);
} else {
const fixedWidthStrArr = this.splitByWidth(
dish.name,
this.singleCharLengthPerLine-countAndPriceLength
);
fixedWidthStrArr.forEach((str, index) => {
if (index === 0) {
this.oneLine(str, `x${dish.count}`);
} else {
this.line(str);
}
});
const nameArr = dish.name.split('\n');
for (let i=0; i<nameArr.length; i++) {
const name = nameArr[i];
const fixedWidthStrArr = this.splitByWidth(
name,
this.singleCharLengthPerLine-countAndPriceLength
);
fixedWidthStrArr.forEach((str, index) => {
if (i===0 && index === 0) {
this.oneLine(str, `x${dish.count}`);
} else {
this.line(str);
}
});
}
}
if (specificationInNewLine) {
dish.specifications?.forEach((str, index) => {
if (str) {
this.line(' * '+str+' *');
const strArr = str.split('\n');
strArr.forEach((specString)=>{
this.line(' * '+specString+' *');
});
}
});
}
Expand Down
37 changes: 22 additions & 15 deletions src/esc-pos-img-encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,25 +530,32 @@ export default class EscPosImgEncoder extends EscPosEncoder {
if(countFront){
this.line((dish.count>1?`${dish.count}x `:'')+dish.name);
}else {
const fixedWidthStrArr = this.splitByWidth(
dish.name,
this.CVS.width - countAndPriceLength
);
fixedWidthStrArr.forEach((str, index) => {
if (dish.count <= 0) {
return;
}
if (index === 0) {
this.oneLine(str, `x${dish.count}`);
} else {
this.line(str);
}
});
const nameArr = dish.name.split('\n');
for(let i=0; i<nameArr.length; i++) {
const name = nameArr[i];
const fixedWidthStrArr = this.splitByWidth(
name,
this.CVS.width - countAndPriceLength
);
fixedWidthStrArr.forEach((str, index) => {
if (dish.count <= 0) {
return;
}
if (i===0 && index === 0) {
this.oneLine(str, `x${dish.count}`);
} else {
this.line(str);
}
});
}
}
if (specificationInNewLine) {
dish.specifications?.forEach((str, index) => {
if (str) {
this.line(' ※ '+str+' ※');
const strArr = str.split('\n')
strArr.forEach((specString)=>{
this.line(' ※ '+specString+' ※ ');
})
}
});
}
Expand Down

0 comments on commit 89ed4bd

Please sign in to comment.