What is restore-cursor?
The restore-cursor npm package is designed to restore the CLI cursor when a Node.js application exits. It ensures that the cursor is visible and functioning correctly after the application has finished running, which is particularly useful for CLI tools that manipulate the cursor visibility.
What are restore-cursor's main functionalities?
Restoring cursor on exit
This feature ensures that the cursor is restored when the process exits, either normally or due to an error. The code sample demonstrates how to use the package to automatically restore the cursor when the process exits.
const restoreCursor = require('restore-cursor');
restoreCursor();
Other packages similar to restore-cursor
cli-cursor
The cli-cursor package allows for showing and hiding the cursor in the terminal. It provides more granular control compared to restore-cursor, which is focused on restoring the cursor state upon exit.
on-exit-leak-free
While not specifically focused on cursor restoration, on-exit-leak-free allows you to run cleanup code when a process exits. It could be used in conjunction with cursor manipulation code to achieve a similar effect to restore-cursor.
restore-cursor
Gracefully restore the CLI cursor on exit
Prevent the cursor you have hidden interactively from remaining hidden if the process crashes.
It does nothing if run in a non-TTY context.
Install
npm install restore-cursor
Usage
import restoreCursor from 'restore-cursor';
restoreCursor();