Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Terminal task list reborn! Create beautiful CLI interfaces via easy and logical to implement task lists that feel alive and interactive.
The listr2 npm package is a powerful utility for creating beautiful and interactive command-line interfaces (CLI) with tasks lists. It allows developers to manage and execute multiple tasks in a structured and visually appealing way. It supports concurrent tasks, nested tasks, and customizable rendering, making it suitable for complex CLI applications.
Basic Task Execution
This feature allows for the execution of a series of tasks, each represented by a title and a task function. The tasks are executed sequentially, and the progress is visually represented in the CLI.
const { Listr } = require('listr2');
const tasks = new Listr([
{
title: 'Task 1',
task: () => Promise.resolve('First task result')
},
{
title: 'Task 2',
task: () => Promise.resolve('Second task result')
}
]);
tasks.run().catch(err => console.error(err));
Concurrent Tasks
This feature demonstrates how to run tasks concurrently. By setting the 'concurrent' option to true, tasks within the same group are executed in parallel, improving performance for independent tasks.
const { Listr } = require('listr2');
const tasks = new Listr([
{
title: 'Concurrent Tasks',
task: () => {
return new Listr([
{
title: 'Task 1',
task: () => Promise.resolve('First concurrent task result')
},
{
title: 'Task 2',
task: () => Promise.resolve('Second concurrent task result')
}
], { concurrent: true });
}
}
]);
tasks.run().catch(err => console.error(err));
Nested Tasks
This feature showcases the ability to nest tasks within other tasks. It is useful for structuring complex workflows where tasks have sub-tasks, allowing for better organization and readability.
const { Listr } = require('listr2');
const tasks = new Listr([
{
title: 'Parent Task',
task: () => {
return new Listr([
{
title: 'Nested Task 1',
task: () => Promise.resolve('First nested task result')
},
{
title: 'Nested Task 2',
task: () => Promise.resolve('Second nested task result')
}
]);
}
}
]);
tasks.run().catch(err => console.error(err));
Ora is a terminal spinner library that provides a similar visual feedback mechanism as listr2 but focuses solely on indicating the progress of ongoing tasks without the structured task list approach. It's simpler for use cases that require only a spinner.
Inquirer.js is a comprehensive library for creating interactive CLI prompts. While it doesn't manage tasks like listr2, it complements it by handling user inputs in a structured way, making it suitable for CLI applications that require both user interaction and task management.
Chalk is a styling library that allows developers to customize the terminal text appearance. Although it doesn't offer task management functionalities like listr2, it's often used alongside listr2 to enhance the visual output of tasks by adding colors and styles.
Create beautiful CLI interfaces via easy and logical to-implement task lists that feel alive and interactive.
FAQs
Terminal task list reborn! Create beautiful CLI interfaces via easy and logical to implement task lists that feel alive and interactive.
We found that listr2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.