Skip to main content

Crate inkling

Crate inkling 

Source
Expand description

§inkling

Reveal arbitrary ASCII art as a progress indicator.

A normal progress bar maps a scalar 0..=1 onto how much of a line is filled. inkling generalises that to two dimensions: it maps progress onto the order in which the glyphs of a picture appear. Give it a dragon and it paints the dragon as your task runs.

§Install

[dependencies]
inkling-loader = "0.2"

It publishes as inkling-loader (the short name was taken) but imports as inkling. Want the command-line tool rather than the library? That is the inkling-cli crate (cargo install inkling-cli), which lets any language drive a reveal through a pipe.

§Quick start

The easy front door is Loader: make one with a total, advance it from anywhere, and a living reveal paints itself until you finish.

use inkling::prelude::*;

let loader = Loader::new(100);
for _ in 0..100 {
    // ... a slice of work ...
    loader.inc(1);
}
loader.finish();

Or wrap any iterator and forget about it:

use inkling::prelude::*;

for _item in (0..100).inkling() {
    // ... work ...
}

§The one idea

Everything turns on a single abstraction, the RankMap: every ink cell of the art is assigned a reveal rank in 0..=1, and a cell is visible exactly when rank <= progress. Because rank is fixed and monotonic, the reveal can never run backwards, any progress value renders directly (it is seekable and resumable), and the whole thing is pure.

How ranks are assigned is the single pluggable seam: an Ordering. The flagship Geodesic ordering traces the “spine” of the art and reveals along it, so a serpent paints from one tip to the other, around every coil, with no per-art configuration.

use inkling::{Art, ordering::{Ordering, Geodesic}};

let art = Art::parse("/\\__/\\\n\\____/");
let ranks = Geodesic::default().rank(&art);

// The pure, dependency-free view: render the half-revealed frame as text.
let frame = inkling::frame::to_string(&art, &ranks, 0.5);
assert_eq!(frame.lines().count(), art.height() as usize);

§Features

FeatureDefaultWhat it adds
terminalyesThe live renderer: Loader, render::Reveal, colour. Pulls in crossterm.
unicodeyesReal display widths for CJK and emoji, via unicode-width.

With neither, the core (art, rank, ordering, easing, frame, width) is pure std with no dependencies at all.

Re-exports§

pub use art::Art;
pub use easing::Easing;
pub use ordering::Ordering;
pub use rank::RankMap;
pub use width::glyph_cols;
pub use loader::Handle;
pub use loader::Loader;
pub use loader::ProgressIteratorExt;
pub use render::ColorDepth;
pub use render::Palette;
pub use render::Style;

Modules§

art
The immutable art model: a rectangular grid of glyphs.
easing
Easing functions map linear time 0..=1 onto eased progress 0..=1.
frame
Pure, dependency-free description of a single reveal frame.
loader
Loader: the ergonomic, thread-safe front door to Inkling.
ordering
Orderings turn Art into a RankMap.
prelude
The handful of imports most programs want, in one glob: use inkling::prelude::*;.
rank
RankMap: the reveal schedule.
render
Terminal rendering.
width
How many terminal columns a glyph occupies.