Files
yinx-cli/lib/menu.js
2025-12-16 16:21:26 +08:00

91 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 };