Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Get some user input
term.magenta("Enter your name: ");
term.inputField((error: any, input: any) => {
term.green("\nYour name is '%s'\n", input);
});
function terminate() {
term.grabInput(false);
setTimeout(() => {}, 100);
}
term.bold.cyan("Type anything on the keyboard...\n");
term.green("Hit CTRL-C to quit.\n\n");
term.grabInput({ mouse: "button" });
term.on("key", (name: string, matches: any[], data: any) => {
console.log("'key' event:", name);
if (name === "CTRL_C") {
terminate();
}
});
term.on("terminal", (name: string, data: any) => {
console.log("'terminal' event:", name, data);
});
term.on("mouse", (name: string, data: any) => {
console.log("'mouse' event:", name, data);
});
drawTemplate(workingContent)
return {
content, // Just the content
workingContent: workingContent, // Content with cursor
finished: finished, // Boolean about whether finished
currentSite: nextSite, // Number of current site
currentEntry: entry, // User input in current site
}
}
const newTemplateState = await handleInput(templateState)
Object.assign(templateState, newTemplateState)
term.grabInput( );
term.on( 'key' , async function( name , _matches , _data ) {
const newTemplateState = await handleInput(templateState, name)
if (newTemplateState.finished) {
term.clear()
terminate()
onComplete(newTemplateState)
}
Object.assign(templateState, newTemplateState)
} ) ;
}
function start(){
// Only start when inactive
if(isActive){ return; }
isActive = true;
// Listen for input
term.grabInput(true);
term.on('key', function(keyName, matches, data){
// Has that key been assigned?
if(keys.hasOwnProperty(keyName)){
keys[keyName].command();
}
// Manually handle the exit command
if(keyName === 'CTRL_C'){
terminate();
return;
}
});
// Render the keys to screen
renderKeys();
}
function terminate() {
term.grabInput(false);
setTimeout(() => {}, 100);
}
function terminate() {
term.grabInput( false ) ;
setTimeout( function() { process.exit() } , 100 ) ;
}
export function exit(code: number = 0) {
terminal.grabInput(false);
terminal.hideCursor(false);
terminal.fullscreen(false);
flushConsole(terminal);
terminal.processExit(code);
}
function terminate(){
term.grabInput(false);
setTimeout(function(){
process.exit();
}, 100);
}
const handleClose = async () => {
terminal.grabInput(false);
Object.keys(runningProcesses)
.forEach((name) => {
const cp = runningProcesses[name];
if (!cp) return;
log(`Stopping ${name}...`);
runningProcesses[name] = null;
if (typeof cp.clear === 'function') {
cp.clear();
} else {
cp.kill();
}
});
};
const handleClose = async () => {
terminal.grabInput(false);
stopProcesses(runningProcesses, (name) => {
runningProcesses[name] = null;
});
};