Elegant CLI helper for NodeJS terminal apps.
Note: APIs may change in near future releases. The APIs are expected to get stable after the first major release (v1.0.0). You can help improve the APIs / API format by raising an issue.
npm install --save cli-pen
Currently, the tools provided by cli-pen include:
- Pen
- ProgressBar
- Spinner
A pen is a simple console utility to replace your console.log
usage in the NodeJS terminal apps.
const { Pen } = require('cli-pen');
const pen = Pen();
pen.info('Console some information.');
pen.warn('Some warning', {
format: ':symbol :message',
});
options
are optional. If not provided, default values are used.
Type: object
Type: string
Default: :symbol :title :message\n
Type: object | string
Default: gray
Note: If a string is used, all types error
info
success
warning
(for :message
) use the same color.
You can provide an object for custom color configuration like:
{
error: 'red',
info: 'white',
success: 'green',
warning: 'yellow'
}
Type: object | string
Default: error: red
info: blue
success: green
warning: yellow
Note: If a string is used, all types error
info
success
warning
(for :title
) use the same color.
You can provide custom colors for titles in a similar way as for color
.
Type: object | string
Default: error: error
info: info
success: success
warning: warning
Note: If a string is used, all types error
info
success
warning
(for :title
) use the same text.
Type: WriteableStream
Default: process.stderr
Stream to write on terminal.
Options: process.stdout
-
.error(message [, options]) Write an error message to console.
-
.info(message [, options]) Write an info message to console.
-
.success(message [, options]) Write a success message to console.
-
.warning(message [, options]) Write a warning message to console.
-
.log(message) An alternative to native
console.log
. Use it in a similar fashion.
Type: string | Array<string>
Type: object
A typical options parameter example would be like:
{
format: ':symbol :message\n',
color: 'blue',
}
A simple ProgressBar for terminal apps.
const { ProgressBar } = require('cli-pen');
const progress = ProgressBar(30);
progress.tick(10);
setTimeout(() => {
progress.tick(20);
console.log('task completed.');
}, 1500);
total
is the number of ticks to complete.
A single call on tick increments the progress by 1
. If an optional progress
is passed, the progress is increments by that number.
A simple Spinner for terminal apps.
const { Spinner } = require('cli-pen');
const spinner = Spinner({
color: 'blue',
});
spinner.start();
If a string is provided, it would work as options.text
.
Type: object
Type: string
Text to display after the spinner.
Type: string
Default: :spinner :text
Type: string
object
Default: line
You can look for list of available spinners here.
Type: string
Default: white
Values: black
red
green
yellow
blue
magenta
cyan
white
gray
Color of the spinner.
Type: WriteableStream
Default: process.stderr
Stream to write on terminal.
Options: process.stdout
Starts the spinner.
Stops the spinner.
Stops the spinner with an information message
.
Stops the spinner with a success message
.
Stops the spinner with a warning message
.
Stops the spinner with a failure message
.
Change the text of the spinner
Change the color of the spinner
CLI-PEN is inspired by some amazing cli tools as ora, progress and few others.
CLI-PEN aims to be a fully featured cli tool for terminal apps built on NodeJS.
MIT © Yatharth Khatri