@kya-os/cli
Version:
CLI for KYA-OS MCP-I setup and management
54 lines • 1.98 kB
JavaScript
import chalk from "chalk";
import readline from "readline";
export async function showScreen(content, options = { requireInput: true }) {
const { requireInput = true, inputKey = "Enter", clearBefore = true, clearAfter = false, prompt = "Press Enter to continue...", } = options;
if (clearBefore) {
console.clear();
}
console.log(content);
if (requireInput) {
console.log("\n" + chalk.gray(prompt));
await waitForKey(inputKey);
}
if (clearAfter) {
console.clear();
}
}
async function waitForKey(expectedKey = "Enter") {
return new Promise((resolve) => {
// Handle non-TTY environments (like CI)
if (!process.stdin.isTTY) {
// In non-TTY environments, just resolve immediately
resolve();
return;
}
readline.emitKeypressEvents(process.stdin);
process.stdin.setRawMode(true);
const handleKeypress = (str, key) => {
// Always cleanup first
process.stdin.setRawMode(false);
process.stdin.removeAllListeners("keypress");
process.stdin.pause();
// Check for the expected key
if (expectedKey === "Enter" && key && (key.name === "return" || key.name === "enter")) {
resolve();
}
else if (key && key.ctrl && key.name === "c") {
// Handle Ctrl+C gracefully
process.exit(0);
}
else if (expectedKey !== "Enter" && str === expectedKey) {
resolve();
}
else {
// If wrong key, re-enable and keep waiting
process.stdin.setRawMode(true);
process.stdin.on("keypress", handleKeypress);
process.stdin.resume();
}
};
process.stdin.on("keypress", handleKeypress);
process.stdin.resume();
});
}
//# sourceMappingURL=screen-manager.js.map