增加转格式
This commit is contained in:
14
lib/grid.js
14
lib/grid.js
@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user