Merge pull request #2 from mrMiiao/master

Improve some panic stuff
This commit is contained in:
Artemy Egorov 2022-08-11 17:25:31 +03:00 committed by GitHub
commit 1290beea1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View file

@ -14,8 +14,8 @@ pub struct Interpreter {
}
impl Interpreter {
pub fn new(input: String) -> Interpreter {
Interpreter {
pub fn new(input: String) -> Self {
Self {
input,
vars: HashMap::new(),
pos: 1,
@ -219,8 +219,8 @@ impl Interpreter {
fn input(&self, value: &String) -> Value {
let mut input = String::new();
print!("{}", value);
io::stdout().flush().unwrap_or_default();
io::stdin().read_line(&mut input).unwrap_or_default();
io::stdout().flush().expect("Couldn't flush Stdout");
io::stdin().read_line(&mut input).expect("Couldn't read from Stdin");
Value::String(input.trim_end().to_string())
}

View file

@ -1,3 +1,5 @@
#![feature(box_syntax, panic_info_message)]
use clap::Parser;
use std::fs;
use std::time::Instant;
@ -15,6 +17,15 @@ mod interpreter;
use interpreter::Interpreter;
fn main() {
std::panic::set_hook(
box |info| {
eprint!("{msg}", msg = match info.message() {
None => "Program panicked!".to_owned(),
Some(x) => x.to_string()
});
}
);
let start = Instant::now();
let args = Args::parse();