pikru
A pure Rust implementation of pikchr, a PIC-like diagram markup language for creating technical diagrams that generates SVG.
Usage
let svg = pikchr.unwrap;
assert!;
Features
- Pure Rust - No C dependencies, safe and portable
- Light/Dark Mode Support - Generate SVGs with CSS variables that
automatically adapt to
prefers-color-scheme - Drop-in Compatible - Aims for full compatibility with the original C implementation
Light/Dark Mode
Enable CSS variables for automatic light/dark theming:
use ;
let options = RenderOptions ;
let svg = pikchr_with_options.unwrap;
assert!;
The generated SVG includes a <style> block with CSS variables using
light-dark(), so colors automatically adapt to the user's color scheme.
Dependencies
pikru has a minimal dependency footprint (7 direct dependencies by default):
| Crate | Purpose |
|---|---|
| glam | 2D vector math for coordinates and geometry |
| pest | PEG parser generator for the pikchr grammar |
| facet-svg | SVG DOM generation and XML serialization |
| miette | Error reporting with source snippets |
| thiserror | Derive macro for error types |
| enum_dispatch | Efficient shape rendering dispatch |
Optional Features
tracing- Enable debug logging via the tracing crate. Disabled by default for smaller builds.
Development
Testing
The test suite validates output against the original C implementation:
See comparison.html for a side-by-side visual comparison of C vs Rust output.
Pre-commit Hooks
Attribution
pikru is a clean-room Rust implementation inspired by:
-
pikchr by D. Richard Hipp - The original C implementation, released under the 0-clause BSD license. The C source is vendored in
vendor/pikchr-c/for reference during development. -
gopikchr - A Go port of pikchr by @zellyn, which served as inspiration for this Rust implementation.
Continuous Integration
Our CI runs on Depot hosted runners — huge thanks to Depot for sponsoring the compute that keeps the pikru test suite flying.
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.