README
Logress
Log your progress, with Logress!
Install
npm install --production --save logress
Usage
const Logress = require('logress')
const log = new Logress()
log.start(1, 'Loading ...')
setTimeout(() => log.update(1, 'still loading!', { color: 'yellow' }), 1000)
setTimeout(() => log.start(2, 'monkeys are cuter than unicorns!', 'monkey'), 2000)
API
constructor(options = { stream = process.stderr, spinner = 'dots' })
Note: It will gracefully not do anything when there's no TTY or when in a CI.
option | required | type | description | default |
---|---|---|---|---|
stream |
✖ | WritableStream |
a Stream to write the output | process.stderr |
spinner |
✖ | String , Object |
a Default Spinner | dots |
const log = new Logress({
stream: process.stdout,
spinner: 'bouncingBar'
})
log.end([message])
terminates all spinners, restores the cursor, optionally sends a goodbye message out
argument | required | type | description | default |
---|---|---|---|---|
message |
✖ | String |
goodbye text | - |
new Logress().end('bye!')
log.start(id[, text][, spinner])
starts a new spinner instance on the line, sets the line text. (will create the line if it doesn't exit)
argument | required | type | description | default |
---|---|---|---|---|
id |
✔ | String |
line identifier | - |
text |
✖ | String |
line text | - |
spinner |
✖ | String , Object |
assign a new Spinner for this line | inherits default Spinner |
log.update(id[, text][, spinner])
similar to
log.start()
but will update existing spinner rather than start a new one
argument | required | type | description | default |
---|---|---|---|---|
id |
✔ | String |
line identifier | - |
text |
✖ | String |
line text | - |
spinner |
✖ | String , Object |
assign a new Spinner for this line | inherits default Spinner |
const log = new Logress({ spinner: 'monkey' })
log.start('ape', 'I like bananas', { color: 'yellow' })
log.start('angry', 'an angry monkey!', { color: 'red' })
log.stop(id[, text])
terminate spinner at line:
id
, optionally change the text
argument | required | type | description | default |
---|---|---|---|---|
id |
✔ | String |
line identifier | - |
text |
✖ | String |
line text | - |
log.stop('ape')
log.stop('angry', 'no more angry monkey!')
log.set(id[, text])
sets the line text (overwriting any existing spinner). (will create the line if it doesn't exit)
argument | required | type | description | default |
---|---|---|---|---|
id |
✔ | String |
line identifier | - |
text |
✖ | String |
line text | - |
log.set('new', 'custom text')
log.prefix(id, prefix, [, text])
- will terminating any existing spinner
- replaces spinner with a custom prefix
- optionally sets a new line text
- will create the line if it doesn't exit
- will match
prefix
against (:info:
,:success:
,:warning:
,:error:
) and replace with an emoji if matched
argument | required | type | description | default |
---|---|---|---|---|
id |
✔ | String |
line identifier | - |
prefix |
✔ | String |
line prefix | - |
text |
✖ | String |
line text | previous value |
log.prefix('line1', '*')
log.info(id, [, text])
alias to `log.prefix(id, 'ℹ', text)
log.success(id, [, text])
alias to `log.prefix(id, '✔', text)
log.succeed(id, [, text])
alias to `log.prefix(id, '✔', text)
log.warning(id, [, text])
alias to `log.prefix(id, '⚠', text)
log.warn(id, [, text])
alias to `log.prefix(id, '⚠', text)
log.error(id, [, text])
alias to `log.prefix(id, '✖', text)
log.fail(id, [, text])
alias to `log.prefix(id, '✖', text)
Spinners
You can use any of the provided spinners or create your own, See demo/index.js
in this repo if you want to test out different spinners.
License: ISC • Copyright: ahmadnassri.com • Github: @ahmadnassri • Twitter: @ahmadnassri