Terminal Cursor Visibility
The `cursor` library (current version 1.3.5) is a small, cross-platform Python package designed to hide or show the terminal cursor. It provides simple functions for managing cursor visibility in command-line interfaces on both Linux and Windows, and also installs command-line utilities for quick control. Its release cadence is infrequent, indicating a stable and mature utility.
Warnings
- gotcha The terminal cursor will remain hidden even after your Python script exits unless `cursor.show()` is explicitly called. This can be confusing for users.
- gotcha This `cursor` library is specifically for managing the *terminal* text cursor. It does not control graphical mouse cursors (e.g., in GUI applications like Tkinter, Pygame) or database cursors (e.g., in `psycopg2`, `mysql-connector-python`).
- gotcha When running scripts in certain IDEs or environments (e.g., Cursor IDE itself), the terminal output and cursor control might be abstracted or handled differently, potentially leading to unexpected behavior or an inability to hide/show the cursor as expected by the native terminal.
Install
-
pip install cursor
Imports
- cursor
import cursor
Quickstart
import cursor
import time
import atexit
atexit.register(cursor.show) # Ensure cursor is shown on exit
print("Hiding cursor in 3 seconds...")
time.sleep(3)
cursor.hide()
print("Cursor hidden. It will reappear in 5 seconds.")
time.sleep(5)
cursor.show()
print("Cursor shown. Script finished.")