diff --git a/Cargo.lock b/Cargo.lock index e3eb7fb..565f0cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,6 +40,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "is-terminal" version = "0.4.10" @@ -56,6 +62,7 @@ name = "kabel" version = "0.1.0" dependencies = [ "colored", + "hex", "is-terminal", "libkabel", "tracing-subscriber", diff --git a/kabel/Cargo.toml b/kabel/Cargo.toml index 16522a6..2da944f 100644 --- a/kabel/Cargo.toml +++ b/kabel/Cargo.toml @@ -12,3 +12,4 @@ libkabel = { version = "0.1", path = "../libkabel", features = ["pretty-emitter" is-terminal = "0.4" tracing-subscriber = "0.3" colored = "2" +hex = "0.4" \ No newline at end of file diff --git a/kabel/src/main.rs b/kabel/src/main.rs index 642b780..0e9c12e 100644 --- a/kabel/src/main.rs +++ b/kabel/src/main.rs @@ -7,8 +7,27 @@ use libkabel::source::SourceFile; use std::error::Error; use std::io; use std::{env, fs}; +use std::fmt::Write; + fn main() -> Result<(), Box> { + std::panic::set_hook(Box::new(|i| { + eprintln!("{}", "----- Kabel has crashed! -----".red()); + eprintln!("{} {} {}", "--".red(), "THIS IS NOT YOUR FAULT".bold().red(), "--".red()); + eprintln!("{}", "Please report the following Error ID to the Kabel developers, along with your program's complete source code.".red()); + + let mut panic_info = String::new(); + write!(panic_info, "{i}").unwrap(); + let error_id = hex::encode(panic_info); + + eprintln!("{}{}", "Error ID: ".red(), error_id.italic().red()); + eprintln!("{}", "Please, either:".red()); + eprintln!("{}", "- Open an issue at https://git.e3t.cc/tm85/kabel, or".red()); + eprintln!("{}", "- E-Mail the developers at kabel@e3t.cc".red()); + eprintln!("{} {} {}", "-- Remember:".red(), "THIS IS NOT YOUR FAULT".bold().red(), "--".red()); + eprintln!("{}", "----- Kabel has crashed! -----".red()); + })); + let argv: Vec = env::args().collect(); if argv.len() != 2 { println!("Usage: {} ", &argv[0]); @@ -49,7 +68,7 @@ fn main() -> Result<(), Box> { "error: Please report this error to the kabel developers along with your" .red() ); - eprintln!("{}", "fail: program's complete source code. Either"); + eprintln!("{}", "fail: program's complete source code. Either".red()); eprintln!( "{}", "fail: - Open an Issue at https://git.e3t.cc/tm85/kabel, or".red() diff --git a/libkabel/src/lexer/token.rs b/libkabel/src/lexer/token.rs index ef1232b..2305d17 100644 --- a/libkabel/src/lexer/token.rs +++ b/libkabel/src/lexer/token.rs @@ -46,7 +46,7 @@ impl Display for TokenType { TokenType::Minus => write!(f, "-"), TokenType::Plus => write!(f, "+"), TokenType::Star => write!(f, "*"), - TokenType::Semicolon => write!(f, ";\n"), + TokenType::Semicolon => writeln!(f, ";"), TokenType::To => write!(f, "to"), TokenType::Identifier(i) => write!(f, "{i}"), TokenType::Colon => write!(f, ":"),