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

32 lines
871 B
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 boxen from "boxen";
import color from "picocolors";
/**
* 显示带边框的古诗(固定在顶部居中)
* @param {string[]} lines - 诗句数组
* @param {number} perLine - 每行显示几句默认2
*/
export function showPoem(lines, perLine = 2) {
// 合并诗句
const merged = [];
for (let i = 0; i < lines.length; i += perLine) {
merged.push(lines.slice(i, i + perLine).join(""));
}
const content = merged.join("\n");
console.log(
boxen(color.yellow(content), {
padding: { top: 1, bottom: 1, left: 4, right: 4 },
margin: { top: 1, bottom: 1, left: 0, right: 0 },
borderStyle: "double",
borderColor: "cyan",
textAlignment: "center",
float: "center",
})
);
}
// 默认古诗
export const defaultPoem = ["你我皆牛马", "生在人世间", "终日奔波苦", "一刻不得闲"];