Skip to content

Latest commit

Β 

History

56 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Terminal Reprint

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

πŸ‘ͺ All Contributors: 1 🀝 Code of Conduct: Kept πŸ§ͺ Coverage πŸ“ 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);
A terminal printing 'Hello, world! πŸ’–' and a count of how many times it has printed, updating every second.

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.

About

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

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages