Skip to main content

Applying 2020s color science to 1970s terminal user interfaces

Project description

Pretty 🌸 Pretty

Run Tests Publish to GitHub Pages Build Wheels

[ Documentation | Rust Crate | Python Package | Repository ]

🎖️ As featured on Real Python #211

Prettypretty is a Rust library with optional Python integration that brings 2020s color science to 1970s terminals for building awesome terminal user interfaces (TUIs). The intended benefits are twofold:

  • You get to design and build the TUI with all the expressivity and convenience of high-resolution color and color spaces, including the perceptually uniform Oklab whether in Cartesian or polar form, with original or revised lightness.
  • Prettypretty takes care of reconciling the intended appearance with the capabilities of the terminal, the current runtime context including light or dark mode, and the user's preferences, whether they lean FORCE_COLOR or NO_COLOR.

To make that possible, prettypretty provides simple abstractions for terminal and high-resolution colors alike, facilitates seamless conversion between them and common color spaces, and 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. Also, where the Rust library currently is BYO(T)IO, that is, bring your own (terminal) I/O, the Python library comes with a powerful terminal abstraction that makes, say, querying the terminal for the current color theme a breeze.

The Python documentation covers the functionality that currently is Python-only. Over time, I expect to port those features to Rust as well.

Minimum Supported Rust and Python Versions

Prettypretty leverages both programming languages to their fullest and hence requires relatively recent versions:

  • According to cargo-msrv, the minimum supported Rust version is 1.77.2.
  • According to vermin, the minimum supported Python version is 3.11.0.

I expect that, as the project matures, the version lag between minimum and latest versions will grow, as it should.

Scripts

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

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 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.10.0.tar.gz (104.7 kB view details)

Uploaded Source

Built Distributions

prettypretty-0.10.0-cp311-abi3-win_amd64.whl (316.6 kB view details)

Uploaded CPython 3.11+ Windows x86-64

prettypretty-0.10.0-cp311-abi3-win32.whl (304.2 kB view details)

Uploaded CPython 3.11+ Windows x86

prettypretty-0.10.0-cp311-abi3-musllinux_1_2_x86_64.whl (639.3 kB view details)

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

prettypretty-0.10.0-cp311-abi3-musllinux_1_2_i686.whl (662.4 kB view details)

Uploaded CPython 3.11+ musllinux: musl 1.2+ i686

prettypretty-0.10.0-cp311-abi3-musllinux_1_2_armv7l.whl (746.7 kB view details)

Uploaded CPython 3.11+ musllinux: musl 1.2+ ARMv7l

prettypretty-0.10.0-cp311-abi3-musllinux_1_2_aarch64.whl (661.7 kB view details)

Uploaded CPython 3.11+ musllinux: musl 1.2+ ARM64

prettypretty-0.10.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (469.4 kB view details)

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

prettypretty-0.10.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (552.7 kB view details)

Uploaded CPython 3.11+ manylinux: glibc 2.17+ s390x

prettypretty-0.10.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (512.8 kB view details)

Uploaded CPython 3.11+ manylinux: glibc 2.17+ ppc64le

prettypretty-0.10.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (484.3 kB view details)

Uploaded CPython 3.11+ manylinux: glibc 2.17+ ARMv7l

prettypretty-0.10.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (482.9 kB view details)

Uploaded CPython 3.11+ manylinux: glibc 2.17+ ARM64

prettypretty-0.10.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl (487.9 kB view details)

Uploaded CPython 3.11+ manylinux: glibc 2.5+ i686

prettypretty-0.10.0-cp311-abi3-macosx_11_0_arm64.whl (416.7 kB view details)

Uploaded CPython 3.11+ macOS 11.0+ ARM64

prettypretty-0.10.0-cp311-abi3-macosx_10_12_x86_64.whl (420.7 kB view details)

Uploaded CPython 3.11+ macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: prettypretty-0.10.0.tar.gz
  • Upload date:
  • Size: 104.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.6.0

File hashes

Hashes for prettypretty-0.10.0.tar.gz
Algorithm Hash digest
SHA256 3e8cd13920f381ee538dbfffa24f46b3aab758049985d6e152b5f32c385c98dc
MD5 ffa63fbb8c2dd82024c1f753942db9c7
BLAKE2b-256 e61cf09a853f6ff6ded7884d5091e0045592440827238025d3c520a9a4b9e5aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 61b0c32cd606698677730932ad74c0cf24f19ba8703339335c8569f69a687bee
MD5 b6cbfc870940f1884692ed144d256657
BLAKE2b-256 0ad47ef90f680aa960e4e81b36033f6caeff3176fc8267746216df3ab258ea48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 834fb7e25a492ea42d0de44e2da21b7261917fc8e84432a54667b05c2b888b55
MD5 9c847e9a3618f1ec9e2b3473341fe83a
BLAKE2b-256 38c4932f8948b9974778d8c45d2213a1d39786291421c3f4e4fd63b25b516933

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7e57f330d3a10a83553dcaf97764f3b376fa2a38dc3e32ade7c424e176b06e2e
MD5 742d39cad3802e231de0bc07604d4d9a
BLAKE2b-256 91d5af3880b4281628ceafb4b6124549f7b6244e4388db83060f1f9d0e2f0212

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c6143cda1f649df98a691a87250f96387e1f350890e579109db55a6172f003fc
MD5 545145679a2d00461ec3cc264c2f76d1
BLAKE2b-256 ea74cd4af4c9c626e1ea4ea94096f8df6f2fba4fdd2a650aedc1bb7cd48f32c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 f9c001189429e1cb23ed714ddc83983c39211730e9c98357b2c8cd153bff8dfc
MD5 110c52935212c90fb5a971f5da148c0b
BLAKE2b-256 67cd03a37ad579669df20f266178a3f55447347fd85f4f86433fc73f827cce3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 85d8dae033ddc934e85e11090d3d6b85ac18f6cc853b82728f7fc1850791b237
MD5 1a43a0c867f471502440cb0d608c9545
BLAKE2b-256 fa92cb9d37cf610b7c6855493d79e1a415adbc5d84f4287bd48f21ee344b21cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 131081caa1eabcd69d5163c1c9db5bbc4e19b005e219112535739bc13d5030fc
MD5 35397c91ee1e9db5028f8b89d4c23f85
BLAKE2b-256 030056557bb839ce12ddb009d0f0997e70d74565f97e402522ebdb219144954f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 73b0da9fe1ecb21fe836dd0e17d0d5e1c2fb44a1f152b8a1d037e39044706b6d
MD5 66a4c2699e2f23fe589b1d814e8eedf6
BLAKE2b-256 5654c61a34411525aede6f8f399517697ff9fc6d9ae97ff04009de27de2bce89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 50f04b84a72694fd9e9bf509df9aa897d85ee6a464be9217f224b9d782a6be94
MD5 c77e678c9c864edcb90e31ecced70845
BLAKE2b-256 28a6ecfce4d9ee4485360a2bf11e1625feffbe01e5a68d7aa3adb211ffcacc68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a77f6250160591f66cf482f6e41ed3e2c6b28bf1db2e93f906566c0030dc1d4f
MD5 0ab2989476b4dc536c4454803a000279
BLAKE2b-256 10da776adf84ae4ea635564d594a7a2b70bbd25e0c98b7453d61a447b0c928c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5450a1c26cf052c8a1c9726a50742245ed9e0ef9da17f9aa393249e96cf66b1
MD5 fc0d7650e222334f76b7ee388522461d
BLAKE2b-256 26942d84507054207a9d924b649d1911cf35ffc1ad9b4f745966e4d159227cbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 2960b7de189f4794173568286e4d5c4d9c850f8a2cc0da408b29ffd44751d82c
MD5 9e7fcaa65690a84d0a63d5066d2157c0
BLAKE2b-256 4c390ca85677a37b5e2a344e791512740e99e3514f026992f3dabd672fd8ce0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1051d60117bd4c9c9d053dd57d85b32dfa34c0b21c560f535899969ccb5c8569
MD5 db5bbf6e1f693593978a7c2006fd3222
BLAKE2b-256 7db5350bdb9cbbb8db84101e6451c5ff933f7c6bd84d935e495170e36c4bd330

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prettypretty-0.10.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 063e32019266c90225cf076bbf72bb4850ad21c3a72602b356287bf5dc792c42
MD5 3bbcfbe3d507f8ac2e76e8a70f321b3d
BLAKE2b-256 a3f2611931cecb61eeb750757e0b687940d7eaeae2794f2a4dccefc3350653a2

See more details on using hashes here.

Supported by

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