ansi-pretty-print

Crates.ioansi-pretty-print
lib.rsansi-pretty-print
version0.0.2
created_at2025-11-21 12:15:27.315453+00
updated_at2025-12-28 10:15:23.550382+00
descriptionPretty-printing structured data with ANSI color support and ligatures. Mostly used for debug outputs.
homepage
repositoryhttps://github.com/piot/ansi-pretty-print
max_upload_size
id1943463
size13,427
Peter Bjorklund (piot)

documentation

README

ansi-pretty-print

A Rust library for pretty-printing structured data with ANSI color support and ligatures. Mostly used for debug outputs for compilers.

Features

  • ANSI Color Support: Syntax highlighting with customizable colors
  • Indentation Management: Automatic indentation for nested structures
  • Ligature Support: Optional use of Unicode ligatures (←, →, ↔, ϕ)
  • Semantic Coloring: Different colors for keywords, types, literals, operators, etc.
  • Flexible: Toggle colors and ligatures on/off

Installation

Add this to your Cargo.toml:

[dependencies]
ansi-pretty-print = "0.0.1"

Usage

use ansi_pretty_print::Printer;
use std::fmt::Write;

let mut output = String::new();
let mut printer = Printer::new(&mut output)
    .with_colors(true)
    .with_ligature(true);

// Print with semantic coloring
printer.keyword("fn")?;
printer.write(" ")?;
printer.function_name("main")?;
printer.punctuation("()")?;

// Use blocks with automatic indentation
printer.block("", |p| {
    p.line("println!(\"Hello, world!\");")?;
    Ok(())
})?;

println!("{}", output);

License

Licensed under the MIT License. See LICENSE for details.

Copyright (c) 2025 Peter Bjorklund. All Rights Reserved.

Commit count: 0

cargo fmt