# Face
> Build CLI app with joy

## Install

```bash

$ npm install --save face

```

## Example

```javascript

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](https://github.com/substack/minimist)

#### app.cmd(template, callback)
> Execute the callback if the user inputs the template

###### Example

```javascript

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

```javascript

app.opt(["w", "width"], (value) => {

    console.log(value);

});
```

#### app.help(callback)
> Execute the help function if the user inputs -h, --h or nothing

###### Example

```javascript

app.help(() => {

    console.log("Usage: ...");

});

```

#### app.print(string)
> Wrapper for process.stdout. Using [perfume](https://github.com/Voyga/perfume) to stylize output

###### Example

```javascript

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](https://github.com/Voyga/perfume) to stylize output

###### Example

```javascript

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

```javascript

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

```javascript

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](https://github.com/yeoman/update-notifier)

###### Example

```javascript

app.update(require("./package.json"), () => {

    console.log("There's an update for this app!");

});

```

#### app.size
> The terminal window size

###### Example

```javascript

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

```

#### app.on(event, callback)
> Execute the callback on a certain event

###### Example

```javascript

// 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](https://github.com/sindresorhus/cli-cursor)

###### Example

```javascript

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
