[][src]Crate mc_legacy_formatting

A parser for Minecraft's legacy formatting system, created with careful attention to the quirks of the vanilla client's implementation.

Features

  • Iterator-based, non-allocating parser
  • Supports #![no_std] usage (with default-features set to false)
  • Implements the entire spec as well as vanilla client quirks (such as handling of whitespace with the STRIKETHROUGH style)
  • Helpers for pretty-printing the parsed Spans to the terminal
  • Support for parsing any start character for the formatting codes (vanilla uses § while many community tools use &)

Examples

Using SpanIter:

use mc_legacy_formatting::{SpanIter, Span, Color, Styles};

let s = "§4This will be dark red §oand italic";
let mut span_iter = SpanIter::new(s);

assert_eq!(span_iter.next().unwrap(), Span::new_styled("This will be dark red ", Color::DarkRed, Styles::empty()));
assert_eq!(span_iter.next().unwrap(), Span::new_styled("and italic", Color::DarkRed, Styles::ITALIC));
assert!(span_iter.next().is_none());

With a custom start character:

use mc_legacy_formatting::{SpanIter, Span, Color, Styles};

let s = "&6It's a lot easier to type &b& &6than &b§";
let mut span_iter = SpanIter::new(s).with_start_char('&');

assert_eq!(span_iter.next().unwrap(), Span::new_styled("It's a lot easier to type ", Color::Gold, Styles::empty()));
assert_eq!(span_iter.next().unwrap(), Span::new_styled("& ", Color::Aqua, Styles::empty()));
assert_eq!(span_iter.next().unwrap(), Span::new_styled("than ", Color::Gold, Styles::empty()));
assert_eq!(span_iter.next().unwrap(), Span::new_styled("§", Color::Aqua, Styles::empty()));
assert!(span_iter.next().is_none());

Structs

PrintSpanColored

A wrapper around Span that provides colored pretty-printing

SpanIter

An iterator that yields Spans from an input string.

Styles

Styles that can be combined and applied to a Span.

Enums

Color

Various colors that a Span can have.

Span

Text with an associated color and associated styles.