prettier_console
Interactive, colorized command-line UI toolkit for Python — arrow-key menus, ASCII-art banners, colored text, and simple file/folder pickers.
Installation
pip install prettier-console
Requirements: Python 3.8+, and the keyboard package (used for arrow-key navigation and safe_input, will be installed with the package). On Linux, reading keyboard events usually requires running with sudo or granting input-group permissions.
Quickstart
import prettier_console as pc
def say_hello():
print("Hello, world!")
def say_hello_to(name):
print(f"Hello, {name}!")
options = [
{
"text": "hello world",
"color": "green",
"id": "hello",
"func": {"body": say_hello}, # plain callable, no arguments
},
{
"text": "hello, Ada",
"color": "cyan",
"id": "hello_ada",
"func": {"body": say_hello_to, "param": ["Ada"]}, # positional argument(s)
},
]
pc.home_menu("HOME", "Welcome!", options)
██╗ ██╗ ██████╗ ███╗ ███╗ ███████╗
██║ ██║ ██╔═══██╗ ████╗ ████║ ██╔════╝
███████║ ██║ ██║ ██╔████╔██║ █████╗
██╔══██║ ██║ ██║ ██║╚██╔╝██║ ██╔══╝
██║ ██║ ╚██████╔╝ ██║ ╚═╝ ██║ ███████╗
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝
=======================================
Welcome!
Choose from the following 3 options:
>·1.hello world····<
2.hello, Ada
3.quit program
Pressing Enter on "hello world" calls hello_world() with no arguments; pressing Enter on "hello, Ada" calls hello_name("Ada"). Either way, once the handler returns, you're back at this menu — selecting "quit program" is what actually exits (via quit_program()). The options return and quit program is built into the menu(quit program for home_menu(), and return for menu()), so do not add them in the customized choice.
Usage
Colored output
from prettier_console import default_colored_output, colored_output
default_colored_output.print("Build succeeded", color="green")
default_colored_output.print("Warning: low disk space", color="yellow", background="black")
# Or make your own instance (e.g. bright variant)
bright = colored_output(bright=True)
bright.print("Critical error", color="red")
# Get a colored string without printing it (e.g. to embed in another message)
tag = default_colored_output.get_print_string_text("[OK]", color="green")
print(f"{tag} All tests passed")
Banners and headers (ASCII art)
pc.print_banner("prettier_console")
pc.print_header("v1.0 released", color="cyan")
Multi-line input is supported — \n starts a new row of large text:
pc.print_banner("quick brown fox\njumps over the\nlazy dog")
Yes/no and custom menus
answer = pc.print_yesorno("Delete this file?") # returns 'y' or 'n'
choice = pc.print_selections(
"Pick an environment:",
[
{"text": "Development", "color": "green", "id": "dev"},
{"text": "Staging", "color": "yellow", "id": "staging"},
{"text": "Production", "color": "red", "id": "prod"},
],
) # returns the chosen id, navigable with the up/down arrow keys
Full navigable menus
menu() builds a single screen; home_menu() is the entry point of your app (it adds a "quit" option instead of "back", and calls quit_program() when chosen).
def say_hello():
return pc.menu(name="hello world", prompt="hello!", options=None)
def say_hello_to(name):
print(f"Hello, {name}!")
options = [
{
"text": "Say hello",
"color": "red",
"id": "hello",
"func": {"body": say_hello},
},
{
"text": "Say hello to someone",
"color": "blue",
"id": "hello_name",
"func": {"body": say_hello_to, "param": ["Ada"]},
},
]
pc.home_menu(name="HOME", prompt="Welcome!", options=options)
Each option's func is called when selected — either a plain callable, or a {"body": fn, "param": [...]} dict for passing positional arguments. Returning "quit" from a handler exits the whole menu stack.
In order to build dynamic prompt that refreshes when the menu is redrawn, pass a function callback that returns a string.
hw_counter = 0
def say_hello():
return pc.menu(name="hello world", prompt="hello!", options=None)
def prompt_builder():
global hw_counter
hw_counter += 1
return f"hello world for {hw_counter} times!"
options = [
{
"text": "Say hello",
"color": "red",
"id": "hello",
"func": {"body": say_hello},
},
]
pc.home_menu(name="HOME", prompt=prompt_builder, options=options)
Safe input
name = pc.safe_input("What's your name? ")
A drop-in replacement for input() that guards against stray keypresses left over in the input buffer (falls back to normal input() if the keyboard backend isn't available, e.g. on some restricted environments).
File and folder pickers
files = pc.select_files(["jpg", "png"]) # opens a native file dialog, returns a tuple of paths or None
folder = pc.select_folder() # opens a native folder dialog, returns a path or None
Misc utilities
pc.clear_screen() # cross-platform 'cls'/'clear'
width = pc.display_width("你好 world") # display width accounting for full-width CJK characters
pc.quit_program(0) # clears the screen, prints a goodbye message, exits
CLI: adding custom ASCII-art fonts
The banner/header glyphs are stored as JSON under prettier_console/ascii_art_font/font/. You can add or replace a style from a plain-text font file (one row per line, glyph segments for A-Z + space separated by /):
python -m prettier_console.manage updatefont my_font.txt --style retro
python -m prettier_console.manage updatefont my_font.txt --banner # overwrite the default banner style
python -m prettier_console.manage updatefont my_font.txt --header # overwrite the default header style
The previous version of a style is automatically zipped into font/legacy_fonts/ before being overwritten.
API reference
| Function | Description |
|---|---|
colored_output(bright=False) |
Class for producing ANSI-colored output. |
default_colored_output |
Shared colored_output instance used throughout the module. |
display_width(text) |
Display width of a string, counting CJK characters as 2. |
safe_input(prompt="") |
input() replacement resilient to buffered keypresses. |
clear_screen() |
Clears the terminal, cross-platform. |
select_files(file_types) |
Native file-open dialog; returns selected paths or None. |
select_folder() |
Native folder-select dialog; returns a path or None. |
print_yesorno(prompt) |
Arrow-key Yes/No prompt; returns 'y' or 'n'. |
print_selections(prompt, options) |
Arrow-key single-select prompt; returns the chosen option's id. |
print_banner(text, color="white") |
Prints large ASCII-art banner text. |
print_header(text, color="white") |
Prints smaller ASCII-art header text. |
menu(name, prompt, options=None, home=False) |
Renders one navigable menu screen. |
home_menu(name, prompt, options=None) |
Entry-point menu; quits the program via quit_program(). |
quit_program(code=0) |
Clears the screen, prints a goodbye message, exits. |
Worth noticing
When running, do not resize the window of powershell. Otherwise the formatting would break.
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 prettier_console-1.0.0.tar.gz.
File metadata
- Download URL: prettier_console-1.0.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac646b1c3492d926f98cd4ac347c387ff1d5e8043cfe9c3c7a94feeac7dadabf
|
|
| MD5 |
47d2c0cc4d3af519b95d15bbbb3d4257
|
|
| BLAKE2b-256 |
832c66396eb9c126d7e3e32981d0d8722eb17ea8c3ecce38f31b0f0903bb5e20
|
Provenance
The following attestation bundles were made for prettier_console-1.0.0.tar.gz:
Publisher:
publish.yml on Mr-Cosine/prettier_console
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prettier_console-1.0.0.tar.gz -
Subject digest:
ac646b1c3492d926f98cd4ac347c387ff1d5e8043cfe9c3c7a94feeac7dadabf - Sigstore transparency entry: 2811816378
- Sigstore integration time:
-
Permalink:
Mr-Cosine/prettier_console@e5bea902d05d0010b53e3dd92659daa7b68b84e5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Mr-Cosine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5bea902d05d0010b53e3dd92659daa7b68b84e5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file prettier_console-1.0.0-py3-none-any.whl.
File metadata
- Download URL: prettier_console-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ae4c9c54a73f600162f450a0a2feb1c9f72ef42269b79132601ce629b734c29
|
|
| MD5 |
3bd2d8377383290f3a64be6273101623
|
|
| BLAKE2b-256 |
4a9b7b32fdcc21c27ec1a0445005919a1fca66e669d09c5ececeb0d7b5f2667c
|
Provenance
The following attestation bundles were made for prettier_console-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Mr-Cosine/prettier_console
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prettier_console-1.0.0-py3-none-any.whl -
Subject digest:
0ae4c9c54a73f600162f450a0a2feb1c9f72ef42269b79132601ce629b734c29 - Sigstore transparency entry: 2811816387
- Sigstore integration time:
-
Permalink:
Mr-Cosine/prettier_console@e5bea902d05d0010b53e3dd92659daa7b68b84e5 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Mr-Cosine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e5bea902d05d0010b53e3dd92659daa7b68b84e5 -
Trigger Event:
push
-
Statement type: