Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
// Word-wrap this along the full terminal width
term.wrap.yellow(
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);
});
// Word-wrap this along the full terminal width
term.wrap.yellow(
`'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish'`
);
// Word-wrap this inside a column starting at x=10 with a width of 25 terminal cells
term.wrapColumn({ x: 10, width: 25 });
term.wrap.green(
import { terminal as term } from 'terminal-kit'
import { Messenger, MessageEvent, Verification } from '../Messenger';
import { stationToCallsignSSID, isCallsign, isCallsignSSID } from '../utils'
term.on('key', (name: string , matches: string[], data: any): void => {
if ( matches.includes('CTRL_C') || matches.includes('CTRL_D')) {
exit(0)
}
})
type TerminalFunction = (buffer: string) => TerminalFunction // function
const colorMap: { [callsign: string]: TerminalFunction } = {}
const myColorFunction: TerminalFunction = term.cyan
function getColorFunction(callsign: string): TerminalFunction {
const choices = [
term.red,
term.green,
term.yellow,
term.blue,
x: 0,
y: 0,
width: term.width,
height: term.height,
});
b_main.fill({
attr: theme.main,
});
b_main.draw();
// Events
term.on('resize', (width, height) => {
// console.log('TERM RESIZED:', width, height);
load_layout(delta=false);
})
load_layout();
header();
account();
footer();
module.exports = function (input, done) {
log.debug('module.exports: input:', input);
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)
} ) ;
}
const makeCloseChildProcessCallback = name => () => {
if (!(name in runningProcesses)) return;
delete runningProcesses[name];
successLog(`${name} instance stopped.`);
if (Object.keys(runningProcesses).length) {
handleClose();
} else {
doClose();
}
};
terminal.grabInput(true);
terminal.on('key', (key) => {
switch (key) {
case 'CTRL_C': {
if (!confirmClose) {
confirmClose = true;
warnLog('\nGracefully stopping child processes...\n');
log('Press ctrl+c again to force exit.');
log("(This may cause some problems when running 'yarn start' again.)\n");
handleClose();
} else {
process.exit(0);
}
break;
}
case 'h':
case 'H': {
if (showHints) {
const diff = reflowAndDiff(container, renderer);
if (!initialized) {
initialized = true;
initialize(container);
}
flushDiff(diff);
})
);
const node = reconciler.createContainer(container, false, false);
reconciler.updateContainer(element, node, null, () => undefined);
let timeout: NodeJS.Timeout | undefined;
let unmounted = false;
terminal.on('resize', () => {
if (!unmounted) {
unmounted = true;
reconciler.updateContainer(null, node, null, () => undefined);
}
timeout && clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = undefined;
unmounted = false;
reconciler.updateContainer(element, node, null, () => undefined);
}, 1000);
});
}
const selectedPath = path.resolve( current.path, selectedDirectory );
const stats = fs.statSync( selectedPath );
if ( stats.isDirectory() ) {
current = Folder( selectedPath );
} else {
current.index = selectedIndex;
term.bell();
}
render();
} );
};
term.on( 'key', ( name ) => {
switch ( name ) {
case 'BACKSPACE':
const parentPath = path.dirname( current.path );
if ( isProjectPath( parentPath ) ) {
current = Folder( parentPath );
render();
} else {
term.bell();
}
break;
case 'ESCAPE':
term.clear();
fixup: setCommand.bind(null, 'fixup'),
cut: cutLine,
paste: pasteLine,
quit: close.bind(null, input.join('\n')),
abort: close.bind(null, ''),
};
var cmd = keyBindings[key];
if (cmds[cmd]) {
cmds[cmd]();
}
status('Pressed key:' + key + ', Command:' + keyBindings[key] + ' Current line: ' + lineNum);
});
term.on('terminal', function (key) {
switch (key) {
case 'SCREEN_RESIZE':
resetTerminal();
break;
default:
break;
}
});
}