fix pretty_print_to

This commit is contained in:
Mark 2024-06-26 21:05:19 +02:00
parent 1b79cfc08f
commit af1715ef91
2 changed files with 13 additions and 12 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "mers_lib" name = "mers_lib"
version = "0.8.20" version = "0.8.21"
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"

View File

@ -1,27 +1,28 @@
use std::{io::Write, process::exit, sync::Arc}; use std::{io::Write, process::exit, sync::Arc};
use crate::{ use crate::{
errors::CheckError,
prelude_compile::{parse, Source}, prelude_compile::{parse, Source},
theme::ThemeGen, theme::ThemeGen,
}; };
#[cfg(feature = "ecolor-term")] #[cfg(feature = "ecolor-term")]
pub fn pretty_print(src: Source) { pub fn pretty_print(src: Source) {
pretty_print_to(src, &mut std::io::stdout(), DefaultTheme) if let Err(e) = pretty_print_to(src, &mut std::io::stdout(), DefaultTheme) {
eprintln!("{e:?}");
exit(28);
}
} }
/// to print to stdout, use `pretty_print` (available only with the `ecolor-term` feature) /// 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>,
) -> Result<(), CheckError> {
let srca = Arc::new(src.clone()); let srca = Arc::new(src.clone());
match parse(&mut src, &srca) { let parsed = parse(&mut src, &srca)?;
Err(e) => { print_parsed(&srca, parsed.as_ref(), out, theme);
eprintln!("{e:?}");
exit(28);
}
Ok(parsed) => {
print_parsed(&srca, parsed.as_ref(), out, theme);
}
}
} }
pub enum AbstractColor { pub enum AbstractColor {