Efficiently (re)-prints text into your terminal. π¨
npm i terminal-reprintimport { startPrinter } from "terminal-reprint";
let prints = 1;
using printer = startPrinter(() => [
"Hello, world! π",
`I have printed: ${prints} time(s).`,
]);
setInterval(() => {
prints += 1;
printer.reprint();
}, 1000);Calling startPrinter clears the terminal screen, hides the cursor with cli-cursor, and prints the lines returned by the provided print function.
It will then update the screen efficiently whenever the return printer's reprint method is called.
Printer functions receive a PrinterContext object.
Created printers are disposable: they should be created with a using statement.
Upon disposable, they show the cursor again.
startPrinter accepts either a print function or an object containing:
print(required): the same print functionstream(optional): a writable stream to print to (by default,process.stdout)
using printer = startPrinter({
print: () => ["Hello, world! π"],
stream: process.stderr,
});
printer.reprint();The context object provided to print functions contains:
columns: the number of columns in the output streamrows: the number of rows in the output stream
using printer = startPrinter((context) => [
`I have ${context.columns} columns.`,
`I have ${context.rows} rows.`,
]);
printer.reprint();See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md.
Thanks! π
Josh Goldberg β¨ π» π π π€ π π§ π π§ |
π This package was templated with
create-typescript-appusing the Bingo framework.