mirror of
https://github.com/Dummi26/mers.git
synced 2026-01-15 23:22:46 +01:00
add support for custom theming in mers errors
this also includes support for the NoTheme, a theme which doesn't add any color to mers' output. If you compile mers with --no-default-features, the `colored` dependency will disappear and mers_lib will fall back to NoTheme.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "mers"
|
||||
version = "0.8.13"
|
||||
version = "0.8.14"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "dynamically typed but type-checked programming language"
|
||||
@@ -10,8 +10,12 @@ repository = "https://github.com/Dummi26/mers"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[features]
|
||||
default = ["colored-output"]
|
||||
colored-output = ["mers_lib/ecolor-term", "dep:colored"]
|
||||
|
||||
[dependencies]
|
||||
mers_lib = "0.8.13"
|
||||
# mers_lib = { path = "../mers_lib" }
|
||||
# mers_lib = "0.8.14"
|
||||
mers_lib = { path = "../mers_lib" }
|
||||
clap = { version = "4.3.19", features = ["derive"] }
|
||||
colored = "2.1.0"
|
||||
colored = { version = "2.1.0", optional = true }
|
||||
|
||||
@@ -3,6 +3,7 @@ use mers_lib::prelude_compile::*;
|
||||
use std::{path::PathBuf, process::exit, sync::Arc};
|
||||
|
||||
mod cfg_globals;
|
||||
#[cfg(feature = "colored-output")]
|
||||
mod pretty_print;
|
||||
|
||||
#[derive(Parser)]
|
||||
@@ -35,7 +36,14 @@ enum Command {
|
||||
#[command(subcommand)]
|
||||
source: From,
|
||||
},
|
||||
/// Not available, because the colored-output default feature was disabled when building mers!
|
||||
#[cfg(not(feature = "colored-output"))]
|
||||
PrettyPrint {
|
||||
#[command(subcommand)]
|
||||
source: From,
|
||||
},
|
||||
/// Add syntax highlighting to the code
|
||||
#[cfg(feature = "colored-output")]
|
||||
PrettyPrint {
|
||||
#[command(subcommand)]
|
||||
source: From,
|
||||
@@ -82,19 +90,19 @@ fn main() {
|
||||
let srca = Arc::new(src.clone());
|
||||
match parse(&mut src, &srca) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(20);
|
||||
}
|
||||
Ok(parsed) => {
|
||||
let (i1, _, i3) = config.infos();
|
||||
match compile(&*parsed, i1) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(24);
|
||||
}
|
||||
Ok(compiled) => match check(&*compiled, i3) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(28);
|
||||
}
|
||||
Ok(output_type) => eprintln!("{output_type}"),
|
||||
@@ -108,24 +116,24 @@ fn main() {
|
||||
let srca = Arc::new(src.clone());
|
||||
match parse(&mut src, &srca) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(255);
|
||||
}
|
||||
Ok(parsed) => {
|
||||
let (i1, mut i2, i3) = config.infos();
|
||||
match compile(&*parsed, i1) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(255);
|
||||
}
|
||||
Ok(compiled) => match check(&*compiled, i3) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(255);
|
||||
}
|
||||
Ok(_) => {
|
||||
if let Err(e) = compiled.run(&mut i2) {
|
||||
eprintln!("Error while running:\n{e}");
|
||||
eprintln!("Error while running:\n{e:?}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -139,19 +147,19 @@ fn main() {
|
||||
let srca = Arc::new(src.clone());
|
||||
match parse(&mut src, &srca) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(255);
|
||||
}
|
||||
Ok(parsed) => {
|
||||
let (i1, mut i2, _) = config.infos();
|
||||
match compile(&*parsed, i1) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(255);
|
||||
}
|
||||
Ok(compiled) => {
|
||||
if let Err(e) = compiled.run(&mut i2) {
|
||||
eprintln!("Error while running:\n{e}");
|
||||
eprintln!("Error while running:\n{e:?}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -159,8 +167,14 @@ fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "colored-output")]
|
||||
Command::PrettyPrint { source } => {
|
||||
pretty_print::pretty_print(get_source(source));
|
||||
}
|
||||
#[cfg(not(feature = "colored-output"))]
|
||||
Command::PrettyPrint { source: _ } => {
|
||||
eprintln!("feature colored-output must be enabled when compiling mers if you want to use pretty-print!");
|
||||
std::process::exit(180);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn pretty_print(mut src: Source) {
|
||||
let srca = Arc::new(src.clone());
|
||||
match parse(&mut src, &srca) {
|
||||
Err(e) => {
|
||||
eprintln!("{e}");
|
||||
eprintln!("{e:?}");
|
||||
exit(28);
|
||||
}
|
||||
Ok(parsed) => {
|
||||
|
||||
Reference in New Issue
Block a user