Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// ... or even combined with other styles
term.moveTo.cyan(1, 1, "My name is %s, I'm %d.\n", "Jack", 32);
// 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);
// The term() function simply output a string to stdout, using current style
// output "Hello world!" in default terminal's colors
t.terminal("Hello world!\n");
// This output 'red' in red
term.red("red");
// This output 'bold' in bold
term.bold("bold");
// output 'mixed' using bold, underlined & red, exposing the style-mixing syntax
term.bold.underline.red("mixed");
// printf() style formatting everywhere:
// this will output 'My name is Jack, I'm 32.' in green
term.green("My name is %s, I'm %d.\n", "Jack", 32);
// Since v0.16.x, style markup are supported as a shorthand.
// Those two lines produce the same result.
term("My name is ")
.red("Jack")(" and I'm ")
.green("32\n");
term("My name is ^rJack^ and I'm ^g32\n");
// Width and height of the terminal
term("The terminal size is %dx%d", term.width, term.height);
// Move the cursor at the upper-left corner
term.moveTo(1, 1);
// We can always pass additional arguments that will be displayed...
term.moveTo(1, 1, "Upper-left corner");
display.displayHeader = function( config , incomingMessage ) {
if ( config[ 'silent-header' ] ) { return ; }
var key , statusGroup ;
// First line, it depends on the message being a request or a response
if ( incomingMessage.method ) {
// use %s, to avoid having to escape %
term.brightGreen.bold( "%s " , incomingMessage.method ) ;
term.green( "%s " , incomingMessage.path || incomingMessage.url ) ;
}
if ( incomingMessage.httpVersion ) { term.magenta( "HTTP/%s " , incomingMessage.httpVersion ) ; }
if ( incomingMessage.status ) {
statusGroup = Math.floor( incomingMessage.status / 100 ) ;
if ( statusGroup >= 1 && statusGroup <= 2 ) {
term.brightGreen.bold( incomingMessage.status ).green( " %s" , incomingMessage.statusMessage ) ;
}
else if ( statusGroup >= 4 && statusGroup <= 5 ) {
term.brightRed.bold( incomingMessage.status ).red( " %s" , incomingMessage.statusMessage ) ;
}
else {
term.brightYellow.bold( incomingMessage.status ).yellow( " %s" , incomingMessage.statusMessage ) ;
}
.catch(e => ({
error: e.message
}));
});
await page.close();
if (results.error) {
throw Error(results.error);
}
//violations, passes, incomplete, inapplicable
if (results.violations.length) {
term.yellow((url || 'Docsify Index Page') + '\n');
} else {
term.green('✅ ' + (url || 'Docsify Index Page') + '\n');
}
for (const violation of results.violations) {
hasViolations = true;
term.bold(violation.description + '\n');
for (const node of violation.nodes) {
term[colorMap[node.impact] || 'green'](
(node.impact === 'critical' ?'!!':'•') + ' ' + node.impact
);
term(' ' + node.html + '\n');
}
console.log('\n');
}
}
})()
.catch(async e => {
term.inputField((error: any, input: any) => {
term.green("\nYour name is '%s'\n", input);
});
(error: any, input: string) => {
term.green("\nYour name is '%s'\n", input);
}
);
(error: any, input: any) => {
term.green("\nYour command is: '%s'\n", input);
}
);
function( error , input ) {
if ( error )
{
term.red.bold( "\nAn error occurs: " + error + "\n" ) ;
}
else
{
term.green( "\nYour file is '%s'\n" , input ) ;
}
process.exit() ;
}
) ;
function( error , input ) {
term.green( "\nYour command is: '%s'\n" , input ) ;
process.exit() ;
}
) ;