resin-cli-visuals ----------------- [](https://npmjs.com/package/resin-cli-visuals) [](https://npmjs.com/package/resin-cli-visuals) [](https://npmjs.com/package/resin-cli-visuals) [](https://travis-ci.org/resin-io-modules/resin-cli-visuals/branches) [](https://ci.appveyor.com/project/resin-io/resin-cli-visuals/branch/master) [](https://david-dm.org/resin-io-modules/resin-cli-visuals) Join our online chat at [](https://gitter.im/resin-io/chat) Resin CLI UI widgets. Role ---- The intention of this module is to provide a collection of command line widgets to be used by the Resin CLI and its plugins. Installation ------------ Install `resin-cli-visuals` by running: ```sh $ npm install --save resin-cli-visuals ``` Documentation ------------- ## Classes
objectfunction | | drive finder |
| [options] | Object | | scan options |
| [options.interval] | Number | 1000 | interval |
| [options.drives] | Array.<Object> | | current drives |
**Example**
```js
scanner = new DriveScanner driveFinder,
interval: 1000
drives: [
{ foo: 'bar' }
]
```
### driveScanner.stop()
**Kind**: instance method of [DriveScanner](#DriveScanner)
**Summary**: Stop the interval
**Access**: public
**Example**
```js
scanner = new DriveScanner(@driveFinder, interval: 1000)
scanner.stop()
```
## visuals : object
**Kind**: global namespace
* [visuals](#visuals) : object
* [.Spinner](#visuals.Spinner)
* [new Spinner(message)](#new_visuals.Spinner_new)
* [.start()](#visuals.Spinner+start)
* [.stop()](#visuals.Spinner+stop)
* [.Progress](#visuals.Progress)
* [new Progress(message)](#new_visuals.Progress_new)
* [.update(state)](#visuals.Progress+update)
* [.SpinnerPromise](#visuals.SpinnerPromise)
* [new SpinnerPromise(options)](#new_visuals.SpinnerPromise_new)
* [.table](#visuals.table) : object
* [.horizontal(data, ordering)](#visuals.table.horizontal)
* [.vertical(data, ordering)](#visuals.table.vertical)
* [.drive([message])](#visuals.drive) ⇒ Promise.<String>
### visuals.Spinner
**Kind**: static class of [visuals](#visuals)
**Summary**: Create a CLI Spinner
**Access**: public
* [.Spinner](#visuals.Spinner)
* [new Spinner(message)](#new_visuals.Spinner_new)
* [.start()](#visuals.Spinner+start)
* [.stop()](#visuals.Spinner+stop)
#### new Spinner(message)
**Returns**: Spinner - spinner instance
**Throws**:
- Will throw if no message.
| Param | Type | Description |
| --- | --- | --- |
| message | String | message |
**Example**
```js
spinner = new visuals.Spinner('Hello World')
```
#### spinner.start()
**Kind**: instance method of [Spinner](#visuals.Spinner)
**Summary**: Start the spinner
**Access**: public
**Example**
```js
spinner = new visuals.Spinner('Hello World')
spinner.start()
```
#### spinner.stop()
**Kind**: instance method of [Spinner](#visuals.Spinner)
**Summary**: Stop the spinner
**Access**: public
**Example**
```js
spinner = new visuals.Spinner('Hello World')
spinner.stop()
```
### visuals.Progress
**Kind**: static class of [visuals](#visuals)
**Summary**: Create a CLI Progress Bar
**Access**: public
* [.Progress](#visuals.Progress)
* [new Progress(message)](#new_visuals.Progress_new)
* [.update(state)](#visuals.Progress+update)
#### new Progress(message)
**Returns**: Progress - progress bar instance
**Throws**:
- Will throw if no message.
| Param | Type | Description |
| --- | --- | --- |
| message | String | message |
**Example**
```js
progress = new visuals.Progress('Hello World')
```
#### progress.update(state)
**Kind**: instance method of [Progress](#visuals.Progress)
**Summary**: Update the progress bar
**Access**: public
**Parm**: String [state.message] - message
| Param | Type | Description |
| --- | --- | --- |
| state | Object | progress state |
| state.percentage | Number | percentage |
| [state.eta] | Number | eta in seconds |
**Example**
```js
progress = new visuals.Progress('Hello World')
progress.update(percentage: 49, eta: 300)
```
### visuals.SpinnerPromise
**Kind**: static class of [visuals](#visuals)
**Summary**: Create a CLI Spinner that spins on a promise
**Access**: public
**Fulfil**: Object value - resolved or rejected promise
#### new SpinnerPromise(options)
This function will start a Spinner and stop it when the
passed promise is either fulfilled or rejected. The function
returns the passed promise which will be in either rejected or
resolved state.
| Param | Type | Description |
| --- | --- | --- |
| options | Object | spinner promise options |
| options.promise | Promise | promise to spin upon |
| options.startMessage | String | start spinner message |
| options.stopMessage | String | stop spinner message |
**Example**
```js
visuals.SpinnerPromise
promise: scanDevicesPromise
startMessage: "Scanning devices"
stopMessage: "Scanned devices"
.then (devices) ->
console.log devices
```
### visuals.table : object
**Kind**: static namespace of [visuals](#visuals)
* [.table](#visuals.table) : object
* [.horizontal(data, ordering)](#visuals.table.horizontal)
* [.vertical(data, ordering)](#visuals.table.vertical)
#### table.horizontal(data, ordering)
Notice that you can rename columns by using the CURRENT => NEW syntax in the ordering configuration.
**Kind**: static method of [table](#visuals.table)
**Summary**: Make an horizontal table
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| data | Array.<Object> | table data |
| ordering | Array.<String> | display ordering |
**Example**
```js
console.log visuals.table.horizontal [
{ name: 'John Doe', age: 40 }
{ name: 'Jane Doe', age: 35 }
], [
'name => full name'
'age'
]
FULL NAME AGE
John Doe 40
Jane Doe 35
```
#### table.vertical(data, ordering)
Notice that you can rename columns by using the CURRENT => NEW syntax in the ordering configuration.
Vertical tables also accept separators and subtitles, which are represented in the ordering configuration as empty strings and strings surrounded by dollar signs respectively.
**Kind**: static method of [table](#visuals.table)
**Summary**: Make a vertical table
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| data | Object | table data |
| ordering | Array.<String> | display ordering |
**Example**
```js
console.log visuals.table.vertical
name: 'John Doe'
age: 40
job: 'Developer'
, [
'$summary$'
'name => full name'
'age'
''
'$extras$'
'job'
]
== SUMMARY
FULL NAME: John Doe
AGE: 40
== EXTRAS
JOB: Developer
```
### visuals.drive([message]) ⇒ Promise.<String>
The dropdown detects and autorefreshes itself when the drive list changes.
**Kind**: static method of [visuals](#visuals)
**Summary**: Prompt the user to select a drive device
**Returns**: Promise.<String> - device path
**Access**: public
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [message] | String | 'Select a drive' | message |
**Example**
```js
visuals.drive('Please select a drive').then (drive) ->
console.log(drive)
```
Support
-------
If you're having any problem, please [raise an issue](https://github.com/resin-io/resin-cli-visuals/issues/new) on GitHub and the Resin.io team will be happy to help.
Tests
-----
Run the test suite by doing:
```sh
$ gulp test
```
Contribute
----------
- Issue Tracker: [github.com/resin-io/resin-cli-visuals/issues](https://github.com/resin-io/resin-cli-visuals/issues)
- Source Code: [github.com/resin-io/resin-cli-visuals](https://github.com/resin-io/resin-cli-visuals)
Before submitting a PR, please make sure that you include tests, and that [coffeelint](http://www.coffeelint.org/) runs without any warning:
```sh
$ gulp lint
```
License
-------
The project is licensed under the Apache 2.0 license.