listr-simple-tree-renderer
v0.1.3
Published
Listr renderer with simple tree support (non concurrent tasks)
Downloads
2,071
Maintainers
Readme
listr-simple-tree-renderer
Listr simple tree renderer
- Shows simple task list in non-concurrent mode to support long task list (with visible subtask list).
- Inspired by listr-verbose-renderer and listr-update-renderer
- Task spinners are not used to allow rendering tree with history.
- Why this package when we can use listr-update-renderer?
Install
$ npm install --save listr-simple-tree-renderer
Usage
const SimpleTreeRenderer = require('listr-simple-tree-renderer');
const Listr = require('listr');
const list = new Listr([
{
title: 'foo',
task: () => Promise.resolve('bar')
},
{
title: 'Output can be function to change text',
task: (context, task) => {
task.output = () => {
return `${figures.tick} Custom render`
}
}
}
], {
renderer: SimpleTreeRenderer
});
list.run();
Options
These options should be provided in the Listr options object.
indentString
Type: boolean
Default: true
Append every indention based on corresponding level task.
taskIcon
Type: string
Default: pointer
Icon that will be displayed next to the task name. Icon list in figures package
Spinner
Need to show spinner? Use custom rendering which will clear the output before changing task.
const logUpdate = require('log-update')
const ElegantSpinner = require('elegant-spinner')
/**
* Shows spinner and runs given task. Returns value from the promise task.
*
* Do not output any data within promise task.
*
* @param {string} title
* @param {Function} promiseTask
* @return {Promise<any>}
*/
module.exports = async function (title, promiseTask) {
function cancel () {
clearInterval(interval)
logUpdate.clear()
}
const spinner = ElegantSpinner()
// Show the spinner
const interval = setInterval(() => {
logUpdate(spinner() + ' ' + title)
}, 100)
try {
const response = await promiseTask()
cancel()
return response
} catch (e) {
cancel()
throw e
}
}
task = {
title: 'test',
task: (context, task) => showSpinner('Loading', async () => {
return await somethingThatWillReturnTitle()
}).then((title) => {
task.output = title
})
}
Related
- listr - Terminal task list
- listr-update-renderer - Listr update renderer
- listr-silent-renderer - Suppress Listr rendering output
License
MIT © Martin Kluska