优化第一阶段

This commit is contained in:
yinsx
2025-12-22 12:07:12 +08:00
parent dd99e932b4
commit 1df41ac4ab
38 changed files with 340 additions and 300 deletions

21
lib/utils/terminal.js Normal file
View File

@ -0,0 +1,21 @@
export function clearScreen() {
process.stdout.write("\x1Bc");
}
export function strWidth(str = "") {
let width = 0;
for (const char of String(str)) {
width += char.charCodeAt(0) > 127 ? 2 : 1;
}
return width;
}
export function padEnd(str, width) {
const value = String(str);
return value + " ".repeat(Math.max(0, width - strWidth(value)));
}
export function centerPad(text, totalWidth) {
const pad = Math.max(0, Math.floor((totalWidth - strWidth(text)) / 2));
return " ".repeat(pad);
}