terminal-reprint
TypeScript icon, indicating that this package has built-in type declarations

0.1.0Β β€’Β PublicΒ β€’Β Published

Terminal Reprint

Efficiently (re)-prints text into your terminal. πŸ–¨

πŸ‘ͺ All Contributors: 1 🀝 Code of Conduct: Kept πŸ“ License: MIT πŸ“¦ npm version πŸ’ͺ TypeScript: Strict

Usage

npm i terminal-reprint
import { startPrinter } from "terminal-reprint";

let prints = 1;

using printer = startPrinter(() => [
	"Hello, world! πŸ’–",
	`I have printed: ${prints} time(s).`,
]);

setInterval(() => {
	prints += 1;
	printer.reprint();
}, 1000);

startPrinter

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 Options

startPrinter accepts either a print function or an object containing:

  • print (required): the same print function
  • stream (optional): a writable stream to print to (by default, process.stdout)
using printer = startPrinter({
	print: () => ["Hello, world! πŸ’–"],
	stream: process.stderr,
});

printer.reprint();

PrinterContext

The context object provided to print functions contains:

  • columns: the number of columns in the output stream
  • rows: the number of rows in the output stream
using printer = startPrinter((context) => [
	`I have ${context.columns} columns.`,
	`I have ${context.rows} rows.`,
]);

printer.reprint();

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! πŸ’–

Contributors

Josh Goldberg ✨
Josh Goldberg ✨

πŸ’» πŸ–‹ πŸ“– πŸ€” πŸš‡ 🚧 πŸ“† πŸ”§

πŸ’ This package was templated with create-typescript-app using the Bingo framework.

Readme

Keywords

none

Package Sidebar

Install

npm i terminal-reprint

Weekly Downloads

69

Version

0.1.0

License

MIT

Unpacked Size

13.8 kB

Total Files

16

Last publish

Collaborators

  • joshuakgoldberg