mirror of
https://github.com/thumbsup/thumbsup
synced 2024-11-19 09:26:04 +00:00
bf60ae4677
- This component was not published to the rpm registry anyway - We depended on the repo’s master branch which can break things for everyone - Its repo was not getting much attention which meant * no tests, no coverage report * no linting * no package linting (e.g. had 2 dependencies that weren’t actually used) It will be simpler to manage this way
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
|
|
/*
|
|
Special Listr renderer that
|
|
- on every change, renders the whole task list in memory
|
|
- accumulates all rendered data into an array
|
|
- has this array available as `listr._renderer.output`
|
|
*/
|
|
module.exports = class ListrTestRenderer {
|
|
static get nonTTY () {
|
|
return true
|
|
}
|
|
constructor (tasks) {
|
|
this._tasks = tasks
|
|
this.output = []
|
|
}
|
|
render () {
|
|
for (let task of this._tasks) {
|
|
this.subscribe(task)
|
|
}
|
|
}
|
|
subscribe (task) {
|
|
task.subscribe(
|
|
event => {
|
|
if (event.type === 'SUBTASKS') {
|
|
// new subtasks: subscribe to them too
|
|
task.subtasks.forEach(sub => this.subscribe(sub))
|
|
} else {
|
|
// something else happened, capture all titles
|
|
const titles = this.allTitles(this._tasks, 0)
|
|
this.output.push(titles)
|
|
}
|
|
}
|
|
)
|
|
}
|
|
allTitles (tasks, indent) {
|
|
return tasks.map(task => {
|
|
const subTitles = this.allTitles(task.subtasks, indent + 1)
|
|
return ' '.repeat(indent) + task.title + '\n' + subTitles
|
|
}).join('')
|
|
}
|
|
end () {
|
|
}
|
|
}
|