Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

resin-cli-visuals

balena-io-modules4.4kApache-2.03.0.0TypeScript support: included

Resin CLI UI widgets

resin, cli, widgets, text, visuals

readme

resin-cli-visuals

Current Release License Downloads Travis CI status AppVeyor status Dependencies

Join our online chat at Gitter 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:

$ npm install --save resin-cli-visuals

Documentation

Classes

DriveScanner

Objects

visuals : object

DriveScanner

Kind: global class
Summary: Dynamically detect changes of connected drives
Access: protected

new DriveScanner(driveFinder, [options])

Param Type Default Description
driveFinder function | drive finder
[options] Object | scan options
[options.interval] Number 1000 interval
[options.drives] Array.<Object> | current drives

Example

scanner = new DriveScanner driveFinder,
    interval: 1000
    drives: [
        { foo: 'bar' }
    ]

driveScanner.stop()

Kind: instance method of DriveScanner
Summary: Stop the interval
Access: public
Example

scanner = new DriveScanner(@driveFinder, interval: 1000)
scanner.stop()

visuals : object

Kind: global namespace

visuals.Spinner

Kind: static class of visuals
Summary: Create a CLI Spinner
Access: public

new Spinner(message)

Returns: Spinner - spinner instance
Throws:

  • Will throw if no message.
Param Type Description
message String message

Example

spinner = new visuals.Spinner('Hello World')

spinner.start()

Kind: instance method of Spinner
Summary: Start the spinner
Access: public
Example

spinner = new visuals.Spinner('Hello World')
spinner.start()

spinner.stop()

Kind: instance method of Spinner
Summary: Stop the spinner
Access: public
Example

spinner = new visuals.Spinner('Hello World')
spinner.stop()

visuals.Progress

Kind: static class of visuals
Summary: Create a CLI Progress Bar
Access: public

new Progress(message)

Returns: Progress - progress bar instance
Throws:

  • Will throw if no message.
Param Type Description
message String message

Example

progress = new visuals.Progress('Hello World')

progress.update(state)

Kind: instance method of 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

progress = new visuals.Progress('Hello World')
progress.update(percentage: 49, eta: 300)

visuals.SpinnerPromise

Kind: static class of 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

visuals.SpinnerPromise
         promise: scanDevicesPromise
         startMessage: "Scanning devices"
         stopMessage: "Scanned devices"
 .then (devices) ->
         console.log devices

visuals.table : object

Kind: static namespace of visuals

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
Summary: Make an horizontal table
Access: public

Param Type Description
data Array.<Object> table data
ordering Array.<String> display ordering

Example

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
Summary: Make a vertical table
Access: public

Param Type Description
data Object table data
ordering Array.<String> display ordering

Example

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
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

visuals.drive('Please select a drive').then (drive) ->
    console.log(drive)

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

Tests

Run the test suite by doing:

$ gulp test

Contribute

Before submitting a PR, please make sure that you include tests, and that coffeelint runs without any warning:

$ gulp lint

License

The project is licensed under the Apache 2.0 license.

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

v1.4.2 - 2018-05-07

v3.0.0

(2025-06-06)

  • Bump etcher-sdk to v10.0.0 [Otavio Jacobi]
  • Drop support to node18 [Otavio Jacobi]

v2.0.1

(2024-09-12)

  • Remove moment [myarmolinsky]

v2.0.0

(2024-04-08)

  • Update etcher-sdk to v9.0.7 [Thodoris Greasidis]
  • Update TypeScript to 5.4.4 [Thodoris Greasidis]
  • Drop supoport for node < 18 [Thodoris Greasidis]

v1.8.4

(2023-12-19)

  • Remove repo config from flowzone.yml [Kyle Harding]

v1.8.3

(2023-05-24)

  • Fix the drive widget failing to instantiate the DynamicList [Thodoris Greasidis]

v1.8.2

(2023-05-09)

  • Configure pseudo tty emulation for flowzone [Felipe Lalanne]

v1.8.1

(2023-05-08)

  • Update etcher-sdk to v8 [Felipe Lalanne]
  • Setup flowzone [Felipe Lalanne]

v1.8.0

(2021-03-01)

  • package: Bump etcher-sdk to v6.2.0 [Marios Balamatsias]

v1.7.2

(2020-08-17)

  • Fix missing param [Pagan Gazzard]

v1.7.1

(2020-08-17)

  • Update dependencies [Pagan Gazzard]
  • Update etcher-sdk to 4.x [Pagan Gazzard]

1.7.0 - 2020-03-09

  • Update dependencies [Pagan Gazzard]

1.6.0 - 2020-03-09

  • Switch to using the drive scanner from etcher-sdk [Pagan Gazzard]

1.5.2 - 2020-03-06

  • Convert dynamic-list to typescript [Pagan Gazzard]

1.5.1 - 2020-03-06

  • Add linting [Pagan Gazzard]

1.5.0 - 2020-03-03

  • Bring inquirer-dynamic-list into the module so it uses inquirer 7.x [Pagan Gazzard]

1.4.7 - 2020-03-03

  • Remove build output from the repo [Pagan Gazzard]

1.4.6 - 2020-02-29

  • Remove underscore.string [Pagan Gazzard]
  • Update to lodash 4.x [Pagan Gazzard]

1.4.5 - 2020-02-28

  • Lazy-load inquirer-dynamic-list and drivelist [Pagan Gazzard]

1.4.4 - 2019-10-14

  • Update drivelist import (fix balena-cli "os initialize") [Paulo Castro]

1.4.3 - 2019-05-29

  • Dependencies: update to Node 12 compilation [Gergely Imreh]

  • refactor(progress.js): setup moment duration format before use [HAKASHUN]

v1.4.1 - 2018-03-01

  • Upgrade(package): Update to drivelist@6.0.4 [Jonas Hermsmeier]
  • Allow updater to specify custom message [Theodor Gherzan]
  • Test(ci): Fix Node versions used on CI [Jonas Hermsmeier]
  • Doc(README): Fix badge links [Jonas Hermsmeier]
  • Test(ci): Update Node versions tested against on CI [Jonas Hermsmeier]
  • Doc(README): Regenerate README with updated jsdoc2md [Jonas Hermsmeier]
  • Chore(build): Update build files [Jonas Hermsmeier]
  • Upgrade(package): Bump dependencies [Jonas Hermsmeier]

1.4.0 - 2017-06-09

Changed

  • Hide the progress ETA if not specified, rather than assuming it to be 0s

1.3.1 - 2017-05-10

Changed

  • Upgrade drivelist to v5.0.20.

1.3.0 - 2016-10-15

Added

  • Add SpinnerPromise class.

1.2.9 - 2016-05-03

Changed

  • Upgrade drivelist to get recent drive detection improvements.

1.2.8 - 2015-12-04

Changed

  • Omit tests from NPM package.

1.2.7 - 2015-12-02

Changed

  • Improve no available drives message.

1.2.6 - 2015-10-27

Changed

  • Upgrade Inquirer to v0.11.0.

1.2.5 - 2015-10-13

Changed

  • Improve "No available drives" message.

1.2.4 - 2015-10-06

Changed

  • Prevent submission on drive widget when no available drives.

1.2.3 - 2015-10-01

Changed

  • Make drive widget dynamic.

1.2.2 - 2015-08-26

Changed

  • Assume eta to be zero if it doesn't exist.
  • Fix Progress unit test intermittent failures.

1.2.1 - 2015-08-24

Changed

  • Fix spinner memory leak when calling start() multiple times.

1.2.0 - 2015-08-20

Added

  • Support passing a custom message to drive widget.

1.1.0 - 2015-08-13

Added

  • Add drive widget.