Skip to content

How to update progress bar in place? #22

@stefek99

Description

@stefek99

There is an existing example that updates progress bar in place: https://github.com/nathanpeck/clui/blob/master/examples/progress.js (60 lines in total)

There is much simpler example directly in the readme: https://github.com/nathanpeck/clui/blob/master/README.md (4 lines only)

var clui = require('clui');

var Progress = clui.Progress;

var thisProgressBar = new Progress(20);
console.log(thisProgressBar.update(10, 30));

So I've added setInterval so that it updates the progress. I've also added line to clear the console and new console.log with each interval:

var clui = require('clui');

var Progress = clui.Progress;

var value = 50;

var thisProgressBar = new Progress(20);

console.log(thisProgressBar.update(value, 100));

var intervalId = setInterval(function() {
	value++;
	// console.log("Updated value: " + value);

	process.stdout.write('\033c'); // clearing the console
	console.log(thisProgressBar.update(value, 100));

	if (value === 100) {
		clearInterval(intervalId);
	}
}, 500)

In the example with countdown spinner I don't have clear the console and do console.log, see example: https://github.com/nathanpeck/clui/blob/master/README.md#spinnerstatustext

Ideally I would like to do just thisProgressBar.update(value, 100) and the progress bar should be updated in places easily...

(without clearing the existing console - I may have so many other progress bars and elements running)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions