Terminal manipulation utilities for Python applications, including ANSI color codes, cursor control, text styling, and interactive output formatting
Project description
Termite: Terminal Utilities
Terminal manipulation utilities for Python: colors, styles, emojis, cursor-control and string-based formatting.
Features
- text-colors
- basic named colors
- arbitrary hex, rgb, or rgba(which gets blended back to rgb)
- sum to merge colors, e.g. BLUE + RED
- highlight-colors
- basic named colors
- arbitrary hex, rgb, or rgba(which gets blended back to rgb)
- sum to merge colors, e.g. BLUE + RED
- styles
- bold
- italic
- underline
- strikethrough
- cursor actions
- write_ahead/save/restore
- clear/erase
- up/down/left/right
- pos/row/col
- emojis
:fire=> 🔥
- special fonts and ASCII art
- Big Text
- Boxed Text
- Markdown Rendering using
termite-md
How to use
- in Python
- in the command-line
Install
pip install modularizer-termite
Quick Start
from termite import subprint, full_demo
subprint("GREEN[BOX[BIG[hello, world]]]\nBGYELLOW[Termite can do a lot :fire:]")
full_demo()
Tools
from termite import t: access pretty much any const or builderprint(t.GRAY + "some text" + t.RST)orprint(t.GRAY("some text"))
from termite import sub: do string substitutions to get the fancy stringfrom termite import subprint: do string substitutions then print the fancy stringfrom termite import cprint: each statement overwrites the last, print with black text and gray completions, built for an autocomplete solutiontermite.raw: JUST the strings, none of our fancy classes or getterstermite.chars.CTRL: object which gets the key equivalents of Ctrl combos, e.g.CTRL + 'c',CTRL["c"],CTRL.C
String Substitution with sub()
The sub() function provides a declarative string-based API for terminal formatting.
Basic Usage
from termite import sub, subprint
a = sub("RED[text] GREEN[text] BLUE[text]")
b = sub("BOLD[bold] ITALIC[italic] UNDERLINE[underline]")
subprint("BOLDRED[Error message]")
Stacked Keys
Stack multiple keys together. Keys are matched longest-first (e.g., RED before R):
from termite import sub, subprint
x = sub("BOLDITALICREDBLU[bold italic merged red+blue]")
subprint("BOLDUNDERLINEGREENYELLOW[bold underline green+yellow]")
Merged Colors
Multiple colors are automatically merged by averaging RGB values:
from termite import subprint
subprint("BLUERED[merged blue+red]")
subprint("GREENYELLOW[green+yellow]")
subprint("REDBLUEGREEN[three colors merged]")
Short Aliases
B= BOLD,I= ITALIC,U= UNDERLINE,D= DIM,S= STRIKETHROUGH,R= REVERSE,H= HIDDEN
from termite import subprint
subprint("B(bold) I(italic) U(underline)")
subprint("BOLD+ITALIC+UNDERLINE[bold italic underline]")
Cursor Control
from termite import subprint
subprint("LEFT RIGHT UP DOWN") # Default: 1
subprint("LEFT[3] RIGHT[5] UP[2] DOWN[4]") # With args
subprint("POS[10,20] ROW[5] COL[10]") # Positioning
subprint("CLEAR ERASE BACK") # Line control
subprint("WA[GRAY[completion]]") # Write ahead
RGB Colors
from termite import subprint
subprint("rgb[#FF5733][custom orange]")
subprint("rgb[#258][shorthand]")
subprint("rgb[255,100,50][RGB tuple]")
subprint("bgrgb[#0000FF][background]")
Nested Patterns
from termite import subprint
subprint("GREEN[BOLD[bold green]]")
subprint("RED[BOLD[UNDERLINE[nested]]]")
subprint("GREEN[BOLD[FGRGB[#FF0000][red inside]]]")
Examples
from termite import subprint
# Status messages
subprint("GREEN[✓ Success] RED[✗ Error]")
# Progress
for i in range(10):
subprint(f"BOLD[Progress: ]GREEN[{i+1}/10]", end="")
subprint("CLEAR")
# Interactive completion
pre="prefix"
completion="test"
subprint(f"{pre}WA[GRAY[{completion}]]")
Colors API
from termite import colors
# Foreground colors
colors.red("text")
colors.green("text")
colors.bright_red("text")
# Background colors
colors.bg.blue("text")
# Styles
colors.bold("text")
colors.italic("text")
# RGB colors
colors("#FF5733")("text")
colors((255, 87, 51))("text")
# Combining
colors.bold + colors.red("text")
colors(foreground="red", background="blue", style="bold")
Cursor Control
from termite import cursor
cursor.up(n=1) # Move up n lines
cursor.down(n=1) # Move down n lines
cursor.left(n=1) # Move left n chars
cursor.right(n=1) # Move right n chars
cursor.pos(row, col) # Move to position
cursor.col(n=0) # Move to column
cursor.row(n) # Move to row
cursor.clear_line() # Clear to end of line
cursor.erase_line() # Erase entire line
cursor.write_ahead(text) # Write without moving cursor
cursor.backspace() # Backspace
Print with Suggestions
import time
from termite import cprint
cprint("User typed: ", completion="completion")
time.sleep(1)
cprint("User typed: abc", completion="def") # Updates previous
Module Structure
colors.py- Color and styling APIcursor.py- Cursor movement and positioningsub.py- String substitution for formattingterminal.py- High-level printing utilitiesraw- Low-level ANSI codeschars.py- Control character mappingsclie.py- Command Line Interface which calls sub
Project details
Release history Release notifications | RSS feed
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 modularizer_termite-0.1.1.tar.gz.
File metadata
- Download URL: modularizer_termite-0.1.1.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
776daa646a2a3b5684772c545c4c601a6a746e24cbfb331d80ce55a2004fd18d
|
|
| MD5 |
8587f73f46c60c7341911c4b619e41e4
|
|
| BLAKE2b-256 |
a75909e387a8cf75e36419ecfe10adefe4afcf9a0ebc59509b616cad62879728
|
Provenance
The following attestation bundles were made for modularizer_termite-0.1.1.tar.gz:
Publisher:
publish.yml on modularizer/termite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularizer_termite-0.1.1.tar.gz -
Subject digest:
776daa646a2a3b5684772c545c4c601a6a746e24cbfb331d80ce55a2004fd18d - Sigstore transparency entry: 758907040
- Sigstore integration time:
-
Permalink:
modularizer/termite@8e2f8537f2fcce10cebefb6ee88b602627cce49d -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/modularizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e2f8537f2fcce10cebefb6ee88b602627cce49d -
Trigger Event:
release
-
Statement type:
File details
Details for the file modularizer_termite-0.1.1-py3-none-any.whl.
File metadata
- Download URL: modularizer_termite-0.1.1-py3-none-any.whl
- Upload date:
- Size: 62.5 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 |
03a9dd1ee64b5d18b621babc3eb90ce4ac160d28256e04b067cfb8e0b1099eb2
|
|
| MD5 |
2c08ca4b2a7046a72002d438d60b204a
|
|
| BLAKE2b-256 |
824f88f4ee37a118577abd59b7071b095debff75b451e58446246a174765c770
|
Provenance
The following attestation bundles were made for modularizer_termite-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on modularizer/termite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modularizer_termite-0.1.1-py3-none-any.whl -
Subject digest:
03a9dd1ee64b5d18b621babc3eb90ce4ac160d28256e04b067cfb8e0b1099eb2 - Sigstore transparency entry: 758907085
- Sigstore integration time:
-
Permalink:
modularizer/termite@8e2f8537f2fcce10cebefb6ee88b602627cce49d -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/modularizer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e2f8537f2fcce10cebefb6ee88b602627cce49d -
Trigger Event:
release
-
Statement type: