An open API service indexing awesome lists of open source software.

https://github.com/derrickpelletier/node-status

Nodejs stdout status and progress bar. Multi-item, various display types.
https://github.com/derrickpelletier/node-status

nodejs progress progress-bar status stdout

Last synced: 16 days ago
JSON representation

Nodejs stdout status and progress bar. Multi-item, various display types.

Awesome Lists containing this project

README

        

# node-status

Makes a little stdout status bar. As simple or complex as you need.

```
npm install node-status
```

- [Config](#config)
- [Item Options](#item-options)
- [Item Methods](#item-methods)
- [Patterns](#patterns)
- [Tokens](#non-item-tokens)

## Example of custom patterns
![image](https://cl.ly/2m3E2629130X/Screen%20Recording%202016-08-23%20at%2012.46%20PM%20(3).gif)

## Example of steps
![image](https://d17oy1vhnax1f7.cloudfront.net/items/2S0x2U0S0L1r3a441O1Q/Screen%20Recording%202016-08-23%20at%2012.37%20PM.gif)

## Quickstart
```javascript
var status = require('node-status')
var pizzas = status.addItem('pizza')

status.start()

pizzas.inc()
pizzas.inc(3)
```

## Config
Status accepts the following config options on `start()`:
+ `invert`: defaults to *false*. Inverts the colors of the bar.
+ `interval`: defaults to 250. Number of milliseconds per re-draw interval.
+ `pattern`: optional manual definition for status bar layout. See [Patterns](#patterns)

```javascript
status.start({
invert: true,
interval: 200,
pattern: 'Doing work: {uptime} | {spinner.cyan} | {pizza.bar}'
})
```

## Item Options

All item options are optional.

| option | type | default | notes |
|---|---|---|---|
| **count** | `number` | `0` | Can specify a starting count if needed. |
| **max** | `number` | `null` | Will cause 'count' type to display as `count/max`. ***Required*** for some display types. Can be a number or a function that returns a number. |
| **custom** | `function` | `null` | a function run when the pattern `{.custom}` is used. Access `this.count` and `this.max` for values if needed. Must return a `string`. |
| **precision** | `number` | `2` | The precision used in percentages. |
| **steps** | `Array` | `false` | An array of strings that identify steps for the item. The count of the item identifies the current step. |

## Item Methods

| method | notes |
|---|---|
| `inc( Number )` | Increases the count on the item by the desired amount. If no amount is specified, will increase by 1. |
| `dec( Number )` | Decreases the count on the item by the desired amount. If no amount is specified, will decrease by 1. |
| `doneStep( success:Boolean, message:String )` | A helper method for when using `steps` on an item. Will stamp the step to the screen with a ✔ when success is `true`, ✖ when false. An optional message can be added which will be appended to the display. See the gif above, or the examples/steps.js |

## Patterns

The pattern setting in status config can be used to layout your bar as you see fit, if the default doesn't suit you. Simply a string of tokens.

The pattern:

```
'Doing work: {uptime} | {spinner.cyan} | {pizza.bar}'
```

Would render as:
```
Doing work: 10s | ⠼ | [▒▒▒▒▒▒----]
```

Tokens are specified as: `{[.color][.modifier]}`.

All tokens support colorization with [marak/colors](https://github.com/Marak/colors.js).

### Non-item tokens

| token | modifiers | notes |
|---|---|---|
| uptime | | renders the current uptime of the process. |
| spinner | spinner types | renders a spinner. Any type available in [cli-spinners](https://github.com/sindresorhus/cli-spinners) can be used. Ex: `{spinner.bouncingBall.cyan}`

### Item tokens

All items use their `name` as tokens. If you add an item named `pizza`, you can render it in the pattern with `{pizza}`. Simple.

#### Item type modifiers
The items have a number of types available to render.

| type | example | |
|---|---|---|
| default | `5` or `5/10` | With no type specified, item is rendered as the `count`, or the `count/max` if `max` was specified. |
| percentage | 15.23% | Renders a simple percentage, requires `max` to be set. Uses the `precision` setting to round the value. |
| custom | anything | Renders whatever is returned by the specified `custom` function. |
| bar | `[▒▒▒▒▒-----]` | Renders as a progress bar. Requires `max` to be set. |
| time | 15s | Uses the count as milliseconds and renders the value as a nicely formatted time. |

## Using Console.log alongside status
Right now, if you have to use `console.log` after the status bar has started, it can be a bit janky because the stdout line isn't cleared when a console.log is run.

You can utilize an extended console.log by adding this after requiring status.
```javascript
console = status.console()
```