增加转格式

This commit is contained in:
yinsx
2025-12-20 11:51:35 +08:00
parent 5315a97613
commit d9abc57b0b
32 changed files with 4339 additions and 229 deletions

View File

@ -1,6 +1,16 @@
import color from "picocolors";
import { initKeypress, onKey } from "./keyboard.js";
function clearScreen() {
if (process.stdout.isTTY) {
process.stdout.write("\x1b[2J"); // clear screen
process.stdout.write("\x1b[3J"); // clear scrollback
process.stdout.write("\x1b[H"); // move cursor home
} else {
console.clear();
}
}
// 计算字符串显示宽度
function strWidth(str) {
let width = 0;
@ -35,7 +45,7 @@ export async function gridSelect(options) {
const pad = " ".repeat(Math.max(0, Math.floor((termWidth - totalWidth) / 2)));
function render() {
console.clear();
clearScreen();
if (renderHeader) {
console.log(renderHeader());
@ -110,7 +120,7 @@ export async function gridSelect(options) {
setImmediate(() => resolve(items[current]));
} else if (key.name === "escape" || (key.ctrl && key.name === "c")) {
process.stdin.setRawMode(false);
console.clear();
clearScreen();
console.log(color.yellow("👋 再见!"));
process.exit(0);
}