@sapphirecode/tasks
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@sapphirecode/tasks

version: 1.0.0

Progress displays for large amounts of tasks

Installation

npm:

npm i --save @sapphirecode/tasks

yarn:

yarn add @sapphirecode/tasks

Usage

// Create at least one vertical task list to contain all your tasks
const list = new TaskListVertical;

// Have some asychronous task, that can send progress updates
async function mock_task (task: Task): Promise<void> {
  const duration = (Math.random () * 10) + 2;
  for (let i = 0; i < duration; i++) {
    // set the task progress between 0.0 and 1.0
    task.progress = i / duration;
    if (task.progress > 0.8)
      task.color = chalk.blue; // change the color of the task at any time

    await new Promise ((resolve) => setTimeout (resolve, 1000));
  }
  task.completed = true; // mark the task as completed
  task.color = chalk.green;
}

// start your tasks
for (let i = 0; i < 10; i++) {
  // horizontal task lists can be used to group tasks and give them a label
  const lv = new TaskListHorizontal;
  lv.label = `Task ${i}`;
  lv.label_length = 10; // the label length is used to align the progress bars between all horizontal lists
  for (let j = 0; j < 10; j++) {
    const task = new Task;
    lv.tasks.push (task);
    mock_task (task);
  }
  list.tasks.push (lv);
}

// call update once to render the task list
// the display will automatically stop, once all tasks are completed
list.update ();

await list.await_end (); // await the completion of all tasks

License

MIT © Timo Hocker timo@scode.ovh

Package Sidebar

Install

npm i @sapphirecode/tasks

Weekly Downloads

45

Version

1.0.3

License

MIT

Unpacked Size

19.9 kB

Total Files

25

Last publish

Collaborators

  • timoho01