Skip to content
PcoiDev edited this page Oct 4, 2025 · 2 revisions

Description

Edit printed terminal text using ANSI escape codes.

Why Mutable Print?

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.

Installation

pip install mutable-print

How it works?

Internally, mutable-print:

  • Keeps a global list of all printed lines.
  • Calculates the cursor position relative to past prints.
  • Moves the cursor up using \033[A and clears lines with \033[2K.
  • Reprints from the updated index to maintain correct order.

This enables retroactive edits even after printing additional lines.

Clone this wiki locally