Spectrum.ExnPrinter that raises exceptions on invalid color/style tags.
Prepare a formatter to handle color tags. Returns a reset function to restore original formatter state.
This enables Spectrum's tag processing on a Format.formatter, allowing you to use @{<tag>content@} syntax in your format strings. The returned function restores the formatter to its original state.
(* Basic usage with stdout *)
let reset = Spectrum.prepare_ppf Format.std_formatter in
Format.printf "@{<green>Success:@} Operation completed@.";
Format.printf "@{<bold>%d@} items processed@." 42;
reset () (* Using with a custom formatter *)
let buffer = Buffer.create 256 in
let fmt = Format.formatter_of_buffer buffer in
let reset = Spectrum.prepare_ppf fmt in
Format.fprintf fmt "@{<red>Error:@} Something went wrong@.";
Format.pp_print_flush fmt ();
reset ();
let result = Buffer.contents buffer in
Printf.printf "Captured: %s\n" result (* Multiple formatters simultaneously *)
let reset_out = Spectrum.prepare_ppf Format.std_formatter in
let reset_err = Spectrum.prepare_ppf Format.err_formatter in
Format.printf "@{<green>Info:@} Starting process@.";
Format.eprintf "@{<yellow>Warning:@} Low memory@.";
reset_out ();
reset_err ()module Simple : sig ... endSimple one-shot printing interface that handles formatter setup/teardown.