第一版

This commit is contained in:
yinsx
2025-12-16 16:21:26 +08:00
parent 0c73ef2547
commit 8ba7e635f5
15 changed files with 1006 additions and 30 deletions

90
lib/menu.js Normal file
View File

@ -0,0 +1,90 @@
import color from "picocolors";
import boxen from "boxen";
import figlet from "figlet";
import { gridSelect } from "./grid.js";
// 古诗配置
let poemConfig = {
lines: ["你我皆牛马", "生在人世间", "终日奔波苦", "一刻不得闲"],
perLine: 2,
padding: { top: 2, bottom: 2, left: 6, right: 6 },
borderStyle: "double",
borderColor: "cyan",
};
// 标题配置
let titleConfig = {
text: "Zguiy Tool Box",
font: "Standard",
color: "magenta",
};
// 工具列表
const tools = [
{ name: "KTX2 纹理压缩", desc: "图片转KTX2格式", module: "./lib/ktx2/index.js" },
{ name: "模型压缩", desc: "压缩glTF/GLB模型", module: "./lib/model/index.js" },
{ name: "图片批量处理", desc: "裁剪/缩放/转换", module: "./lib/image/index.js" },
{ name: "Sprite图集", desc: "合并精灵图集", module: "./lib/sprite/index.js" },
{ name: "LOD生成器", desc: "生成多级细节", module: "./lib/lod/index.js" },
{ name: "音频压缩", desc: "压缩音频文件", module: "./lib/audio/index.js" },
];
// 设置古诗
export function setPoem(lines, perLine = 2) {
poemConfig.lines = lines;
poemConfig.perLine = perLine;
}
// 设置古诗框样式
export function setPoemStyle(style) {
Object.assign(poemConfig, style);
}
// 设置标题
export function setTitle(text, font = "Standard", titleColor = "magenta") {
titleConfig.text = text;
titleConfig.font = font;
titleConfig.color = titleColor;
}
// 渲染古诗
function renderPoem() {
const merged = [];
for (let i = 0; i < poemConfig.lines.length; i += poemConfig.perLine) {
merged.push(poemConfig.lines.slice(i, i + poemConfig.perLine).join(""));
}
return boxen(color.yellow(merged.join("\n")), {
padding: poemConfig.padding,
borderStyle: poemConfig.borderStyle,
borderColor: poemConfig.borderColor,
textAlignment: "center",
float: "center",
});
}
// 渲染标题
function renderTitle() {
const art = figlet.textSync(titleConfig.text, { font: titleConfig.font });
const termWidth = process.stdout.columns || 80;
return art.split("\n").map(line => {
const pad = Math.max(0, Math.floor((termWidth - line.length) / 2));
return " ".repeat(pad) + color[titleConfig.color](line);
}).join("\n");
}
// 渲染头部
function renderHeader() {
return renderPoem() + "\n\n" + renderTitle();
}
// 主菜单
export async function showMainMenu() {
return gridSelect({
items: tools,
cols: 3,
colWidth: 24,
renderHeader: renderHeader,
});
}
export { tools, poemConfig, titleConfig };