# bar-provider

> Easy configuration for LemonBoy's bar

Latest version **2.0.2** (published 2016-01-14) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install bar-provider
pnpm add bar-provider
yarn add bar-provider
bun add bar-provider
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2016-01-14 |
| First published | 2014-11-05 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Florian Albertz |
| Maintainers | paulavery |
| Keywords | LemonBoy, bar, bar ain't recursive |

## Links

- npm: https://www.npmjs.com/package/bar-provider
- Repository: https://github.com/PaulAvery/node-bar-provider
- Homepage: https://github.com/PaulAvery/node-bar-provider#readme
- Issues: https://github.com/PaulAvery/node-bar-provider/issues
- npm.io page: https://npm.io/package/bar-provider

## Dependencies (1)

- [co](https://npm.io/package/co.md) ^3.1.0

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2016-01-14
- 2.0.1 — 2015-09-14
- 2.0.0 — 2015-05-12
- 1.0.2 — 2015-02-25
- 1.0.1 — 2014-11-05
- 1.0.0 — 2014-11-05

## README

bar-provider
============
[![Build Status](https://img.shields.io/travis/PaulAvery/node-bar-provider.svg?style=flat)](https://travis-ci.org/PaulAvery/node-bar-provider)

This module provides a way to easily define data to be piped into LemonBoy's [bar](https://github.com/LemonBoy/bar). It depends on generators, so run node with the `--harmony` flag (or use io.js).

Quickstart
----------
*bar.js*

```js
var Bar = require('bar-provider');
var bar = new Bar();

bar
	.button('dmenu_run', 'Menu')
	.center(function *() {
		return new Date();
	})
	.interval(1000);
```

Now you can pipe it to bar

	$ node --harmony bar.js | bar


API
---
This module provides a chainable api to allow easy construction of a bar layout.
Whenever any data should be provided to a method, you may pass a string or a generator function returning a string. Any generator function will be run through [co](https://github.com/tj/co) and its return value will be rendered.

### Adding data

#### bar.raw(data)
Simply append raw text

#### bar.left(data)
Prefixes with `%{l}`

#### bar.right(data)
Prefixes with `%{r}`

#### bar.center(data)
Prefixes with `%{c}`

#### bar.color(color, data)
Prefixes with `%{F<color>}` and postfixes with `%{F}`

#### bar.bg(color, data)
Prefixes with `%{B<color>}` and postfixes with `%{B}`

#### bar.button(cmd, data)
Prefixes `%{A:<cmd>:}` and postfixes with `%{A}`

### Chaining
You may chain all the provided methods. If you omit the data argument, all the chained styles apply at once.
So the following will give you blue background AND white text:

```js
bar.bg('blue').color('white', 'Some Data');
```

while the following will print text on blue background followed by white text:

```js
bar.bg('blue', 'Some Data').color('white', 'Some more Data')
```

### Rendering

#### bar.render()
Generator function which, when run through `co` outputs a single line on the console.

#### bar.renderCo()
`bar.render()` wrapped via `co`. This returns immediately.

#### bar.interval(ms)
Normal function, which calls the render function at each interval.

Custom Styling
--------------
To allow styling of data returned from generator functions (think color for battery percentage), each generator function is passed a utility object, containing all the above methods. Simply return the result of a yielded method if neccessary. These may be chained as well

```js
function *getBattery(utils) {
	//somehow get your battery percentage
	var percent = yield getPercentage();
	var color = percent > 50 ? 'green' : 'red';

	return yield utils.color(color, percent);
}

bar.right(getBattery);
```

---
_Source: https://npm.io/package/bar-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
