Need private packages and team management tools?Check out npm Teams »

stdout-update

1.4.1 • Public • Published

stdout-update logo

Build Status npm NPM

Purely and accurately overwrites the previous output in the terminal, while maintaining the history of third-party logs.

Install

Yarn

yarn add stdout-update

NPM

npm install stdout-update

Usage

const { UpdateManager } = require('stdout-update');
 
const manager = UpdateManager.getInstance();
const frames = ['', '', '', '', '', '', '', '', '', ''];
const messages = ['Swapping time and space...', 'Have a good day.', "Don't panic...", 'Updating Updater...', '42'];
let i = (= 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:'], 0);
        manager.unhook(false);
    } else {
        const frame = frames[(= ++% frames.length)];
        const message = messages[(= 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([separateHistory])

Unhooks both stdout and stderr streams and print their story of logs. Returns success status.

separateHistory

Type: boolean

Default: false

If true, will add an empty line to the history output for individual recorded lines and console logs.

update(rows, [from])

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.

from

Type: number

Default: 0

Index of the line starting from which the contents of the terminal are being overwritten.

getLastLength()

Returns last printed rows count.

getOutside()

Returns rows count outside editable area.

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.

License

MIT

Install

npm i stdout-update

DownloadsWeekly Downloads

1,086

Version

1.4.1

License

MIT

Unpacked Size

48.2 kB

Total Files

19

Last publish

Collaborators

  • avatar