This package has been deprecated

Author message:

Package no longer supported. Contact support@npmjs.com for more info.

face

1.0.0 • Public • Published

Face

Build CLI app with joy

Install

 
$ npm install --save face
 

Example

 
const App = require("face");
const app = new App();
 
app.cmd("ask {{name}} {{question}}", (vars) => {
 
    app.println(`Hello (${vars.name}.):green`);
 
    app.ask(`(${vars.question}):blue `, (answer) => {
 
        app.println("Thanks!");
 
    });
 
}).help(() => {
 
    app.println("   Usage:", "bold");
    app.println("      (ask [name] [question]):blue to ask someone a question")
 
});
 

API

app.argv

The parsed user input. Using minimist

app.cmd(template, callback)

Execute the callback if the user inputs the template

Example
 
app.cmd("ask {{name}} {{question}}", (vars) => {
 
    console.log(vars.name);
    console.log(vars.question);
 
});
 

app.opt(opts, callback)

Execute the callback if the user inputs the option

Example
 
app.opt(["w", "width"], (value) => {
 
    console.log(value);
 
});

app.help(callback)

Execute the help function if the user inputs -h, --h or nothing

Example
 
app.help(() => {
 
    console.log("Usage: ...");
 
});
 

app.print(string)

Wrapper for process.stdout. Using perfume to stylize output

Example
 
app.print("Hello (World):red", "bold"); // apply `red` to 'World' and `bold` to the whole
app.print("(:joy:)"); // prints emoji
 

app.println(string)

Wrapper for process.stdout. Using perfume to stylize output

Example
 
app.println("Hello (World):red", "bold"); // apply `red` to 'World' and `bold` to the whole
app.println("(:joy:)"); // prints emoji
 

app.ask(question, callback, options)

Prompt for user input

Example
 
app.ask("Username: ", (answer) => {
 
    console.log(`Your username is ${answer}`);
 
});
 
// Options
 
app.ask("Password: ", (answer) => {
 
    user.password = answer;
 
}, {
 
    hide: true, // hide the text
    mask: "*", // the mask shows instead of the hidden text
    default: "" // the default value
 
});
 

app.store(path, initVal)

Use JSON to store data in path. Creates app.storage to manage data

Example
 
app.store("user.json", {});
app.storage.data.name = "Voyga";
app.storage.save();
 

app.update(path)

Execute the callback if there's an update. Using update-notifier

Example
 
app.update(require("./package.json"), () => {
 
    console.log("There's an update for this app!");
 
});
 

app.size

The terminal window size

Example
 
console.log(app.size.width);
console.log(app.size.height);
 

app.on(event, callback)

Execute the callback on a certain event

Example
 
// Current available events: `exit`, `key`
 
app.on("exit", () => {
 
    app.println("Exit");
 
}).on("key", (key) => {
 
    app.print(key);
 
});
 

app.cursor

Hide and show the cursor. Using cli-cursor

Example
 
app.cursor.hide();
app.cursor.show();
 

app.clearScreen()

Clear the terminal screen

app.clearLine()

Clear a line of output

app.exec(cmd, callback, options)

Wrapper for childProcess.exec

app.exit(code)

Wrapper for process.exit

All functions are chainable

Package Sidebar

Install

npm i face

Weekly Downloads

14

Version

1.0.0

License

MIT

Last publish

Collaborators

  • npm