https://github.com/apparebit/prettypretty

Pretty 🌸 pretty terminals for Rust and Python

https://github.com/apparebit/prettypretty

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.8%) to scientific vocabulary

Keywords

ansi-colors ansi-escape-codes apca-w3 color-contrast color-distance terminal tty

Keywords from Contributors

interactive archival projection charts generic sequences observability autograding hacking shellcodes
Last synced: 5 months ago · JSON representation

Repository

Pretty 🌸 pretty terminals for Rust and Python

Basic Info
Statistics
  • Stars: 51
  • Watchers: 3
  • Forks: 0
  • Open Issues: 0
  • Releases: 8
Topics
ansi-colors ansi-escape-codes apca-w3 color-contrast color-distance terminal tty
Created almost 2 years ago · Last pushed 6 months ago
Metadata Files
Readme License

README.md

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.

Owner

  • Name: Robert Grimm
  • Login: apparebit
  • Kind: user
  • Location: New York City

Software engineer by day. Apocalyptic prophet at night.

GitHub Events

Total
  • Release event: 3
  • Watch event: 6
  • Delete event: 3
  • Issue comment event: 1
  • Push event: 127
  • Pull request review event: 2
  • Pull request event: 4
  • Create event: 4
Last Year
  • Release event: 3
  • Watch event: 6
  • Delete event: 3
  • Issue comment event: 1
  • Push event: 127
  • Pull request review event: 2
  • Pull request event: 4
  • Create event: 4

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 897
  • Total Committers: 2
  • Avg Commits per committer: 448.5
  • Development Distribution Score (DDS): 0.001
Past Year
  • Commits: 687
  • Committers: 2
  • Avg Commits per committer: 343.5
  • Development Distribution Score (DDS): 0.001
Top Committers
Name Email Commits
Robert Grimm a****t@g****m 896
dependabot[bot] 4****] 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 0
  • Total pull requests: 7
  • Average time to close issues: N/A
  • Average time to close pull requests: 6 days
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.14
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 7
Past Year
  • Issues: 0
  • Pull requests: 5
  • Average time to close issues: N/A
  • Average time to close pull requests: 8 days
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 1.2
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 5
Top Authors
Issue Authors
Pull Request Authors
  • dependabot[bot] (7)
Top Labels
Issue Labels
Pull Request Labels
dependencies (7) github_actions (5)

Packages

  • Total packages: 3
  • Total downloads:
    • cargo 7,945 total
    • pypi 175 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 0
    (may contain duplicates)
  • Total versions: 17
  • Total maintainers: 2
pypi.org: prettypretty

Applying 2020s color science to 1970s terminal user interfaces

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 175 Last month
Rankings
Dependent packages count: 11.0%
Average: 36.4%
Dependent repos count: 61.8%
Maintainers (1)
Last synced: 6 months ago
crates.io: prettytty

Simple, lightweight terminal I/O and configuration

  • Versions: 4
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 2,617 Total
Rankings
Dependent repos count: 23.9%
Dependent packages count: 31.7%
Average: 50.4%
Downloads: 95.4%
Maintainers (1)
Last synced: 6 months ago
crates.io: prettypretty

Applying 2020s color science to 1970s terminal user interfaces

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 5,328 Total
Rankings
Dependent repos count: 27.1%
Dependent packages count: 35.9%
Average: 53.2%
Downloads: 96.5%
Maintainers (1)
Last synced: 6 months ago

Dependencies

package-lock.json npm
  • fsevents 2.3.3
  • pyright 1.1.361
package.json npm
  • pyright ^1.1.361
pyproject.toml pypi