-
Notifications
You must be signed in to change notification settings - Fork 0
Intro
PcoiDev edited this page Oct 4, 2025
·
2 revisions
Edit printed terminal text using ANSI escape codes.
Traditional print() writes output that cannot be changed once printed.
mutable-print fixes that you can modify, replace, append, clear, or transform text after it’s been printed.
Perfect for:
- Dynamic CLI output: progress bars, live status updates, etc.
- Retroactive edits: fix or adjust lines even after more output follows.
- Readable terminals: no messy reprints or repeated lines.
- Rich text operations: prepend, append, regex replacement, upper/lower transforms.
All achieved using ANSI escape sequences to move the cursor and redraw content.
pip install mutable-printInternally, mutable-print:
- Keeps a global list of all printed lines.
- Calculates the cursor position relative to past prints.
- Moves the cursor up using
\033[Aand clears lines with\033[2K. - Reprints from the updated index to maintain correct order.
This enables retroactive edits even after printing additional lines.