Package Exports
- stdout-update
- stdout-update/lib/terminal
- stdout-update/lib/wrapper
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stdout-update) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Purely and accurately overwrites the previous output in the terminal, while maintaining the history of third-party logs.
Install
npm install stdout-update
yarn add stdout-update
Usage
const { UpdateManager } = require('../lib/update-manager');
const manager = UpdateManager.getInstance();
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
const messages = ['Swapping time and space...', 'Have a good day.', "Don't panic...", 'Updating Updater...', '42'];
let i = (j = 0);
let ticks = 60;
manager.hook();
console.log(' - log message');
console.error(' - error message');
console.warn(' - warn message');
const id = setInterval(() => {
if (--ticks < 0) {
clearInterval(id);
manager.update(['✔ Success', '', 'Messages:'], 1);
manager.unhook();
} else {
const frame = frames[(i = ++i % frames.length)];
const message = messages[(j = Math.round(ticks / 10) % messages.length)];
manager.update([`${frame} Some process...`, message]);
}
}, 80);
API
getInstance()
Method to get the object to control the streams (stdout
, stderr
) update. Returns UpdateManager
instance.
hook()
Hook stdout and stderr streams. Returns success status.
unhook()
Unhooks both stdout and stderr streams and print their story of logs. Returns success status.
update(rows, [position])
Method to get the object to control the streams (stdout
, stderr
) update. Returns UpdateManager
instance.
rows
Type: string[]
Text lines to write to standard output.
position
Type: number
Default: 0
Index of the line starting from which the contents of the terminal are being overwritten.
isHooked()
Returns the activity status of the hook.
Examples
tasktree-cli - Simple terminal task tree - helps you keep track of your tasks in a tree structure.