fix pretty_print

This commit is contained in:
Mark 2024-06-26 13:02:50 +02:00
parent 7a945e80ba
commit 12d90a8022
2 changed files with 5 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mers_lib" name = "mers_lib"
version = "0.8.16" version = "0.8.17"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "library to use the mers language in other projects" description = "library to use the mers language in other projects"
@ -19,7 +19,6 @@ run = []
ecolor-term = ["dep:colored"] ecolor-term = ["dep:colored"]
ecolor-html = ["dep:html-escape"] ecolor-html = ["dep:html-escape"]
# pretty-print requires ecolor-term, but this is not listed here because I want people to explicitly opt-in to the extra `colored` dependency via the ecolor-term feature.
pretty-print = [] pretty-print = []
[dependencies] [dependencies]

View File

@ -5,13 +5,12 @@ use crate::{
theme::ThemeGen, theme::ThemeGen,
}; };
#[cfg(not(feature = "ecolor-term"))] #[cfg(feature = "ecolor-term")]
compile_error!("feature ecolor-term is required if pretty-print feature is enabled");
pub fn pretty_print(src: Source) { pub fn pretty_print(src: Source) {
pretty_print_to(src, &mut std::io::stdout(), DefaultTheme) pretty_print_to(src, &mut std::io::stdout(), DefaultTheme)
} }
/// to print to stdout, use `pretty_print` (available only with the `ecolor-term` feature)
pub fn pretty_print_to<O: Write>(mut src: Source, out: &mut O, theme: impl FTheme<O>) { pub fn pretty_print_to<O: Write>(mut src: Source, out: &mut O, theme: impl FTheme<O>) {
let srca = Arc::new(src.clone()); let srca = Arc::new(src.clone());
match parse(&mut src, &srca) { match parse(&mut src, &srca) {
@ -65,7 +64,9 @@ pub enum FColor {
Unknown, Unknown,
} }
#[cfg(feature = "ecolor-term")]
pub struct DefaultTheme; pub struct DefaultTheme;
#[cfg(feature = "ecolor-term")]
impl ThemeGen for DefaultTheme { impl ThemeGen for DefaultTheme {
type C = FColor; type C = FColor;
type T = std::io::Stdout; type T = std::io::Stdout;