mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
fix pretty_print
This commit is contained in:
parent
7a945e80ba
commit
12d90a8022
@ -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]
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user