1.0.0 • Published 8 years ago

face v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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

1.0.0

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

11 years ago