Edit printed terminal text using ANSI escape codes.
Project description
mutable-print
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
Usage (API Overview)
mutable_print(*args: Any, sep: str = " ", end: str = "\n", file: Optional[TextIO] = None, flush: bool = False) -> mutable_print
Creates a mutable print object, prints the initial content immediately, and returns a handle to modify it later.
from mutable_print import mutable_print
line = mutable_print("Loading...", flush=True)
line("Done!") # Update the same printed line
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*args |
Any |
— | Values to print |
sep |
str |
" " |
Separator between values |
end |
str |
"\n" |
String appended at the end |
file |
TextIO |
sys.stdout |
Output stream |
flush |
bool |
False |
Whether to flush immediately |
Returns
A mutable_print instance that can be updated or transformed.
__call__(*args: Any, sep: str = " ", end: str = "\n") -> None
Update the content and reprint from this line onward.
line("Processing...", sep=" ", end="\n")
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*args |
Any |
— | New values to print |
sep |
str |
" " |
Separator |
end |
str |
"\n" |
End string |
replace(old: str, new: str, count: int = -1) -> mutable_print
Replace all (or a limited number of) occurrences of a substring in the current content.
line.replace("fail", "success", 1)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
old |
str |
— | Substring to replace |
new |
str |
— | Replacement text |
count |
int |
-1 |
Max occurrences (-1 for all) |
append(*text: str) -> mutable_print
Append text to the end of the content.
line.append("...done")
Parameters
| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to append |
prepend(*text: str) -> mutable_print
Prepend text to the beginning of the content.
line.prepend("[INFO]")
Parameters
| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to prepend |
clear() -> mutable_print
Clear the current content (sets it to an empty string).
line.clear()
set(*text: str) -> mutable_print
Replace the entire content with new text.
line.set("New content")
Parameters
| Name | Type | Description |
|---|---|---|
*text |
str |
Text strings to set as new content |
upper() -> mutable_print
Convert the current content to uppercase.
line.upper()
lower() -> mutable_print
Convert the current content to lowercase.
line.lower()
regex_replace(pattern: str | re.Pattern[str], replacement: str, flags: int = 0) -> mutable_print
Perform a regular expression substitution on the content.
line.regex_replace(r"\d+", "42")
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
pattern |
str | re.Pattern |
— | Regex pattern |
replacement |
str |
— | Replacement string (supports backrefs) |
flags |
int |
0 |
Regex flags (e.g. re.IGNORECASE) |
get() -> str
Retrieve the current content.
text = line.get()
__str__() -> str
String representation of the current content. Called automatically by str(line).
__repr__() -> str
Developer-friendly representation of the object:
mutable_print('Your content here')
Examples
- Basic Update
- Clean and Efficient Loading
- Replace Text
- Append / Prepend
- Clearing and Retrieving Content
- Colored Text
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[Aand clears lines with\033[2K. - Reprints from the updated index to maintain correct order.
This enables retroactive edits even after printing additional lines.
Credits
Developed with ❤️ by PcoiDev
Uses only standard Python modules (sys, re, typing).
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mutable_print-1.0.2.tar.gz.
File metadata
- Download URL: mutable_print-1.0.2.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0beb50eff6181a9f56ced51f756572328063586b9002d36d65d34c5027993c9
|
|
| MD5 |
331695984a0e0f4d36c16c872bf28223
|
|
| BLAKE2b-256 |
03c62e85cb47d56e028366c793b291066a0fb286e6e6d8673142d83f39932272
|
Provenance
The following attestation bundles were made for mutable_print-1.0.2.tar.gz:
Publisher:
release.yaml on PcoiDev/mutable-print
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mutable_print-1.0.2.tar.gz -
Subject digest:
a0beb50eff6181a9f56ced51f756572328063586b9002d36d65d34c5027993c9 - Sigstore transparency entry: 584027276
- Sigstore integration time:
-
Permalink:
PcoiDev/mutable-print@fc093ec161a2094038422ebacbd340a405409aa0 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/PcoiDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@fc093ec161a2094038422ebacbd340a405409aa0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mutable_print-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mutable_print-1.0.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3192b9cb3febe211a6947981627de828e8e36fc53a74354750d1a7a98e1bf74e
|
|
| MD5 |
568278d89eb5c0daf511f830c61321d3
|
|
| BLAKE2b-256 |
9a84648dbb146337758e8e7db6e37201c858974275f67c284accb83a9e1a9aab
|
Provenance
The following attestation bundles were made for mutable_print-1.0.2-py3-none-any.whl:
Publisher:
release.yaml on PcoiDev/mutable-print
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mutable_print-1.0.2-py3-none-any.whl -
Subject digest:
3192b9cb3febe211a6947981627de828e8e36fc53a74354750d1a7a98e1bf74e - Sigstore transparency entry: 584027277
- Sigstore integration time:
-
Permalink:
PcoiDev/mutable-print@fc093ec161a2094038422ebacbd340a405409aa0 -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/PcoiDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@fc093ec161a2094038422ebacbd340a405409aa0 -
Trigger Event:
release
-
Statement type: