Skip to content

Commit

Permalink
Add formatting to main's output
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawdl3y committed Mar 8, 2024
1 parent 5afbcb6 commit fce33b1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,40 @@ fn main() {

// If there isn't already input available in stdin, display a prompt for it
if lines.size_hint().1.is_none() {
print!("Enter dice expression: ");
print!("\x1b[1m\x1b[36mEnter dice expression:\x1b[0m ");
io::stdout().flush().unwrap();
}

// Grab the first line available from stdin
lines.next().unwrap().unwrap()
};

println!("Input: {}", input);
println!("\x1b[1m\x1b[36mInput:\x1b[0m {}", input);

match dicey::parse::term().parse(&input).into_result() {
Ok(ast) => {
println!("Parsed: {:?}", ast);
println!("Deterministic: {}", ast.is_deterministic());
println!("\x1b[1m\x1b[36mParsed:\x1b[0m {:#?}", ast);
println!("\x1b[1m\x1b[36mDeterministic:\x1b[0m {}", ast.is_deterministic());

match ast.eval() {
Ok(evaled) => {
println!();
println!("Evaluated: {:?}", evaled);
println!("Described: {}", evaled);
println!("\x1b[1m\x1b[36mEvaluated:\x1b[0m {:#?}", evaled);
println!("\x1b[1m\x1b[36mDescribed:\x1b[0m {}", evaled);
println!(
"Total: {}",
"\x1b[1m\x1b[36mTotal:\x1b[0m {}",
evaled
.calc()
.map(|total| total.to_string())
.or_else(|err| Ok::<_, dicey::term::Error>(err.to_string()))
.unwrap()
);
}
Err(eval_err) => eprintln!("Evaluation error: {}", eval_err),
Err(eval_err) => eprintln!("\x1b[1m\x1b[31mEvaluation error:\x1b[0m {}", eval_err),
}
}
Err(parse_errs) => parse_errs.into_iter().for_each(|e| eprintln!("Parse error: {}", e)),
Err(parse_errs) => parse_errs
.into_iter()
.for_each(|e| eprintln!("\x1b[1m\x1b[31mParse error:\x1b[0m {}", e)),
};
}

Expand Down

0 comments on commit fce33b1

Please sign in to comment.