1use std::{fmt::Display, process, sync::LazyLock};
2
3static INFO: LazyLock<String> = LazyLock::new(|| {
4 String::from_utf8_lossy(&[
5 27, 91, 51, 52, 109, 27, 91, 49, 109, 73, 78, 70, 79, 58, 32, 27, 91, 109,
6 ])
7 .to_string()
8});
9
10static WARN: LazyLock<String> = LazyLock::new(|| {
11 String::from_utf8_lossy(&[
12 27, 91, 51, 51, 109, 27, 91, 49, 109, 87, 65, 82, 78, 58, 32, 27, 91, 109,
13 ])
14 .to_string()
15});
16
17static ERROR: LazyLock<String> = LazyLock::new(|| {
18 String::from_utf8_lossy(&[
19 27, 91, 51, 49, 109, 27, 91, 49, 109, 69, 82, 82, 58, 32, 27, 91, 109,
20 ])
21 .to_string()
22});
23
24pub fn info<T: Display>(msg: T) {
25 println!("{}{msg}", *INFO);
26}
27
28pub fn warn<T: Display>(msg: T) {
29 println!("{}{msg}", *WARN);
30}
31
32fn gen_build() -> usize {
33 let [major, minor, patch] = env!("CARGO_PKG_VERSION").split(".").collect::<Vec<_>>()[..] else {
34 return 0;
35 };
36
37 let major = major.parse::<usize>().unwrap_or(0);
38 let minor = minor.parse::<usize>().unwrap_or(0);
39 let patch = patch.parse::<usize>().unwrap_or(0);
40
41 (major * 1000) + (minor * 100) + patch
42}
43
44pub fn error<T: Display, F: Display>(msg: T, file: F) -> ! {
45 println!("{}{msg}", *ERROR);
46 println!("{}-------- TRACE --------", *ERROR);
47 println!("{} File: {file}", *ERROR);
48 println!(
49 "{} Edition {}",
50 *ERROR,
51 env!("CARGO_PKG_VERSION").split_at(1).0
52 );
53 println!("{} Lead v{}", *ERROR, env!("CARGO_PKG_VERSION"));
54 println!("{} Build #{}", *ERROR, gen_build());
55 println!("{} Compiled with Rust Nightly", *ERROR);
56 println!("{}-----------------------------", *ERROR);
57 process::exit(1);
58}