Skip to main content

Applying 2020s color science to 1970s terminal user interfaces

Project description

Pretty 🌸 Terminals

Run Tests, Build Wheels, & Publish to PyPI Publish to GitHub Pages

Pretty 🌸 Tty

[ Docs.rs | GitHub Pages | Rust Crate | Repository ]

Prettytty is a lightweight and flexible terminal library for Rust that has only one low-level dependency, i.e., libc on Unix and windows-sys on Windows. Its API is clean and simple: Open a Connection to the terminal and share it across threads as needed. Write Commands to Output. Read Query responses from Input. Scan::read_token takes care of low-level UTF-8 and ANSI escape sequence decoding and Query::parse turns token payloads into objects. A cmd library with 70+ built-in commands covers basic needs and then some.


Pretty 🌸 Pretty:

[ Docs.rs | GitHub Pages | Rust Crate | Python Package | Repository ]

🎖️ As featured on Real Python #211

🎖️ Inspired iTerm2's color preferences

Prettypretty is a Rust library with optional Python bindings that applies 2020s color science to 1970s terminals to facilitate scalable user interfaces. However, instead of progressive enhancement, it primarily relies on graceful degradation from high-resolution colors down to more limited terminal colors.

The three steps for better terminal styles are:

  1. Fluently declare high-resolution styles.
  2. Let prettypretty adjust styles to terminal capabilities and user preferences at program startup.
  3. Use adjusted styles at will.

Prettypretty seamlessly integrates with prettytty for querying the terminal for its current color theme. It then uses said color theme to produce more accurate results when converting high resultion colors down to 256 or 16 terminal colors. The integration also is entirely optional, controlled by the tty feature, and fairly small, requiring about 80 lines of code for Theme::query. Hence integration with another terminal library should be easy enough.

As far as colors are concerned, prettypretty comes with all the expressivity and convenience of high-resolution, floating point colors and color spaces, including the perceptually uniform Oklab, whether in Cartesian or polar form, with original or revised lightness. It further implements state-of-the-art algorithms for gamut-mapping, color interpolation, perceptual contrast, as well as its own hue- and lightness-based downsampling for optimal selection of ANSI colors.

Python Integration

The optional Python integration is enabled with the pyffi feature flag and relies on PyO3 and Maturin for building an extension module with the same functionality. Only where the Rust library uses trait implementations, the Python module uses dedicated methods. While prettytty takes care of terminal access for Rust, the Python version of prettypretty has its own terminal abstraction, with its own Pythonic interface.

Scripts Using Prettypretty

Besides the documentation, a good starting point for familiarizing yourself with prettypretty are the scripts:

  • prettypretty.progress illustrates the library's use on the example of a progress bar in less than 100 lines of Python. The finished progress bar is shown below for both light and dark themes.

    a complete, green progress bar under light mode a complete, green progress bar under dark mode

  • prettypretty.plot charts colors on the chroma/hue plane of Oklab, if you don't feed it colors defaulting to your terminal's current color scheme. Here's the one for the basic theme in Apple's Terminal.app:

    colors from the basic theme for Apple's Terminal.app in Oklch

  • prettypretty.grid visualizes perceptual contrast and color downsampling strategies, exhaustively for the 6x6x6 RGB cube embedded in 8-bit color and selectively for 32x32 slices through the much bigger 24-bit RGB cube.

    a grid visualizing the 6x6x6 embedded RGB cube

  • prettypretty.viz3d traces the boundaries of the visual gamut in 3D and saves the corresponding point cloud or mesh in PLY format. The screenshot below shows Vedo's rendering.

    a 3D visualization of the gamut for visible light,
somewhat shaped like a fat, squat hot pocket

Acknowledgements

I wrote much of prettypretty over a two-month period in 2024. Twice. I first implemented the core color routines in Python and then I did so again in Rust. At this point, only the Rust version survives. But Python remains a tier-1 runtime target for prettypretty. Two things really helped with getting this project started. First, I had been toying with different approaches to terminal styles for a while and knew what I was looking for. Second, I benefitted tremendously from Lea Verou's and Chris Lilley's work on the Color.js library and CSS Color 4 specification. Prettypretty directly reuses Color.js' formulae for conversion between color spaces and implements several CSS Color 4 algorithms.


Copyright 2024-2025 Robert Grimm. The code in this repository has been released as open source under the Apache 2.0 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

prettypretty-0.12.0.tar.gz (161.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

prettypretty-0.12.0-cp311-abi3-win_amd64.whl (459.3 kB view details)

Uploaded CPython 3.11+Windows x86-64

prettypretty-0.12.0-cp311-abi3-win32.whl (442.9 kB view details)

Uploaded CPython 3.11+Windows x86

prettypretty-0.12.0-cp311-abi3-musllinux_1_2_x86_64.whl (803.0 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

prettypretty-0.12.0-cp311-abi3-musllinux_1_2_i686.whl (842.9 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ i686

prettypretty-0.12.0-cp311-abi3-musllinux_1_2_armv7l.whl (903.4 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARMv7l

prettypretty-0.12.0-cp311-abi3-musllinux_1_2_aarch64.whl (802.5 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

prettypretty-0.12.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (632.8 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

prettypretty-0.12.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (663.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ s390x

prettypretty-0.12.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (751.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ppc64le

prettypretty-0.12.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (639.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARMv7l

prettypretty-0.12.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (623.7 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

prettypretty-0.12.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl (680.1 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.5+ i686

prettypretty-0.12.0-cp311-abi3-macosx_11_0_arm64.whl (582.6 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

prettypretty-0.12.0-cp311-abi3-macosx_10_12_x86_64.whl (614.7 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file prettypretty-0.12.0.tar.gz.

File metadata

  • Download URL: prettypretty-0.12.0.tar.gz
  • Upload date:
  • Size: 161.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for prettypretty-0.12.0.tar.gz
Algorithm Hash digest
SHA256 e27349090c3bdf60de2e12ec2f820d00a863f21bb5a98cfaa9e5f75f9447eb7c
MD5 17d61e9197ecc91c32f3e33710b987d9
BLAKE2b-256 fc4eec9fa627d2416175b1d8abd379c723cf3667d58d474458ac1fe8a6efa951

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 03f420a8c3aa3201a8b1b9b57a87380020897ba822a06d025fe582fdd029d66a
MD5 04ad6b4507a25c9cf6a04d7bd823a860
BLAKE2b-256 92a9595a3495e19fd7dab87c4dd962d203e3ef0afb7bec0437a58adbee9af209

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-win32.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 b355edf54ac87fa7a76fa7ec03bc8287c7353e8d6972b522a487b234f801a87a
MD5 9789b123f2d0ea9662005088161bfd13
BLAKE2b-256 b98d8b7ca7f4be1929a42e96805bd3353f69819738bddc48dd0f1aa37487b5de

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fae2b48cdcd13e445c241222e1ceb17b508d3ab1657c1658a1655fa38593c2d2
MD5 68d5396aa543aad035cf11812a2fc4d4
BLAKE2b-256 13a4a98755e9466982da6c6e27c8a3761a93df161ce74b27defac202029ca99f

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1cba2f291f71e9d220eb96014627564a1b1c88bb9f0322951197188a464b573b
MD5 84427594ac0b0ba2e0a325c4dc309649
BLAKE2b-256 d31847461cc286ae7a2362c6d53e9f16471459152f4a7ea60699c719741a1b26

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 16d2fc5cf3419314a5aa72fa9e5bbdf158b2fb187796cc5dd5360368e5ac0253
MD5 bb47ab694d92793eaf30f234d1a53b67
BLAKE2b-256 8444036dcdfbcdf77b11e34b4741777346d7395cf2080e7f5153ca49e386e557

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 768b14d79383827d995ea9e44d54d0a9fe60148a342c9ead9ccd257b20989ab7
MD5 72b7624d6fdadf577c30fee37c194d66
BLAKE2b-256 feb0d7203dd7d8981e34e2d22a68ab996eb66efe7d2621ed53cd692302a68ed0

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64fb0ea0337e54dc84e531c65cae6f40492856bb7fbe78368fb541538cb568de
MD5 c5a5f99ceaf0cc0039b03019c3ccbf7d
BLAKE2b-256 37e85b47b1abd28e1429eadf142bc62300c70d64e06c5b414dcfbd4e71daea7d

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 4463bd454471c18b5a9e2e807eec7ad097c507707cff82a45fe41dbbd14e5573
MD5 ef7997b25324f8f293d31773fac9e156
BLAKE2b-256 5d26519c00a2f7f6645145e29fcc5fa8bcf19dfbc06a54bfc2a984ed57638bdd

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 7122e5ca90d0a4558691548f5851f763d1c352e09768fdcb648f24d563bb63cb
MD5 89cd132516f41681d08a2afffa279dc2
BLAKE2b-256 a290f062e392f81494d6e06399abc04812849976d8f88afce4bc57f6e3134d04

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 250d263af4b091c7030208a47dbe839db6d9ebd12a9417ea8838baedf72518a5
MD5 5ead97643c642e98776f1e0e812cf7c6
BLAKE2b-256 6a5e2f637ae5f5e8ddb46875d9f2406add4fc659aa0c10a08b01ae18a03edc7d

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 792df54bf580dda620aa57ad1648388156cc5a2938055118941592d1a7948b2c
MD5 8979fe25c21fcdafcf6b94a549865eee
BLAKE2b-256 9d8f3189343ee206679cbaf0257d28726c578ab331d8ca4a1bde514734098907

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 c265c02fc51cbc4b69aba062fbc35a8b0f90c8de5aa43f4f53bef40508486f57
MD5 5a43a1fc54601db1900d4595d96ec9eb
BLAKE2b-256 71ca68246b327ab62adf11c67ac5a595b52d1ff17815d1b581be27fcf3d61aea

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4afc4ac3eb8fbfeedea502b5e2d716f1c668fda48d5622de57c4eeff00510b5
MD5 7cffa401867a1079e4e567eb36ee88e6
BLAKE2b-256 a7b0f418c1c6228e286ee8e295f72e81c0c34f26e6a4ca6985364d49cdedbda6

See more details on using hashes here.

File details

Details for the file prettypretty-0.12.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for prettypretty-0.12.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 707d3f99473023bc365f850376adad0e2d005958fbc9dcfd066cb601765fa14d
MD5 8abc205369696ad8fa212ab7ee9f106a
BLAKE2b-256 13ebb94b831a3e7accbe121c7367607d334aa0734fc4593533bae103ec542214

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page