Skip to main content

Crate rich_micro

Crate rich_micro 

Source
Expand description

Micro assets for rs-rich (#565): emoji-sized inline images and animations, written Deploying :micro:rocket:.

Not a port of anything upstream: an rs-rich addition, outside core. Core is unchanged: :micro:name: is not an emoji code, so it passes through core untouched, and every seam here goes through core’s public API (style metadata, Renderable) or rs-rich-ext’s.

  • MicroAsset: a name, a kind, a size in cells (2×1 by default, up to 4×2: 1 to 4 columns, 1 or 2 rows), images, mandatory alt text, an emoji or text fallback, and where it came from.
  • package: .richmicro packages and packs, read under hard Limits.
  • MicroRegistry: built-in < user < trusted project < inline, with aliases, collisions and explain.
  • markup: :micro:name: in markup and text, and in Markdown (PreparedMarkdown); MicroExt and MicroAssetRef in code.
  • render: the placeholder representation, and the MicroRenderer seam that terminal graphics plug into.
  • rows: assets two rows high (a 2×2 icon, a 3×2 animation): MicroRows reserves the row below the line each one sits on, in wrapped text, table cells and panels.
  • graphics: drawing on a terminal: select picks Kitty, iTerm2, Sixel, half-blocks or the text fallback, and MicroGraphics draws with it, in printed output and through the graphics side channel of rich-ext’s live regions and the interactive painter.
  • cache: decoded images fitted to their cells, cached in memory and on disk.
  • pipeline: any picture or animation to an asset’s images: fitted, adjusted, sharpened, with its transparency decided; create writes the package.
  • builtin: the built-in library (status, dev and fun sets), drawn for this project; MicroRegistry::builtin loads it.
use rich::Console;
use rich_micro::{render_markup, FallbackPreference, Layer, MicroAsset, MicroRegistry};

let mut registry = MicroRegistry::new();
registry.add(Layer::Inline, MicroAsset::new("ship", "rocket")?.with_emoji("🚀")?)?;
let console = Console::builder().width(40).build();
let (text, diagnostics) =
    render_markup(&console, "Deploying :micro:ship: :fire:", &registry, FallbackPreference::Emoji);
assert_eq!(text.plain(), "Deploying 🚀 🔥");
assert!(diagnostics.is_empty());

Re-exports§

pub use api::MicroAssetRef;
pub use api::MicroExt;
pub use api::MicroPlugin;
pub use cache::ImageCache;
pub use cache::Prepared;
pub use error::MicroError;
pub use graphics::MicroGraphics;
pub use graphics::MicroMode;
pub use graphics::Selection;
pub use graphics::select;
pub use markup::Diagnostic;
pub use markup::DiagnosticKind;
pub use markup::MarkdownView;
pub use markup::MicroTransform;
pub use markup::PreparedMarkdown;
pub use markup::PreparedMarkup;
pub use markup::expand;
pub use markup::markup_text;
pub use markup::render_markup;
pub use model::AssetKind;
pub use model::CellSize;
pub use model::Fallback;
pub use model::ImageFormat;
pub use model::ImageInfo;
pub use model::ImageRef;
pub use model::Layer;
pub use model::MicroAsset;
pub use model::Origin;
pub use model::PackageLocation;
pub use model::Variants;
pub use name::is_valid_name;
pub use package::Limits;
pub use package::Pack;
pub use registry::Collision;
pub use registry::LoadReport;
pub use registry::MicroRegistry;
pub use registry::MicroRoots;
pub use registry::Rejected;
pub use render::FallbackPreference;
pub use render::FallbackRenderer;
pub use render::MICRO_META_KEY;
pub use render::MicroMeta;
pub use render::MicroRenderer;
pub use render::MicroView;
pub use render::PAD_CELL;
pub use render::Placement;
pub use render::fallback_cells;
pub use render::fallback_row;
pub use render::placeholder;
pub use rows::MicroRows;
pub use rows::reserve_rows;

Modules§

api
The Rust API (#570): an extension trait on core’s Text and a renderable, so micro assets compose with everything else without a core method.
builtin
The built-in library (#581), compiled in: the packs under crates/rich-micro/builtin/, drawn for this project by examples/gen_builtin.rs and read through the same package reader, under the same Limits, as any other pack.
cache
Decoded, fitted images for drawing, cached (#584).
create
Writing packages (#568): the other side of crate::package. What rich micro create runs after the pipeline.
error
Errors.
graphics
Drawing micro assets on a terminal (#572–#577): choosing a protocol, and the renderers and graphics source for each.
image
Image headers read without decoding (#580): the format, the canvas size and the frame count of a PNG, APNG, GIF or WebP, from its container structure alone. Limits are checked on these numbers before anything is ever decoded, so a decompression bomb is refused by its header.
markup
:micro:name: markup (#569, #570).
model
The asset model (#566, #579, #585): what a micro asset is, independent of where it was loaded from or how a terminal will draw it.
name
Asset names: [a-z0-9_-] segments joined by / namespaces.
package
.richmicro packages and packs (#580), read-only.
pipeline
The image and animation pipeline (#571, #572): from any picture to the images a package holds, fitted to its cells.
registry
The layered registry (#567, #583).
render
Placeholder cells and the renderer seam (#577, #578).
rows
Assets two rows high (#711): reserving their rows in any layout.

Structs§

CellPixels
The size of a terminal cell in pixels, as the cache and pipeline take it. The size of one terminal cell in pixels.