From 20cf877d21c6a39b30c2bb1c3b380af62559a747 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 24 Mar 2018 13:20:10 -0700 Subject: [PATCH] Add back color --- schala-repl/src/language.rs | 15 ++++++++++++++- schala-repl/src/lib.rs | 4 ---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 52c3ae4..9dc9c18 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -2,6 +2,7 @@ extern crate colored; use std::collections::HashMap; use self::colored::*; +use std::fmt::Write; pub struct LLVMCodeString(pub String); @@ -94,7 +95,19 @@ impl UnfinishedComputation { impl FinishedComputation { pub fn to_repl(&self) -> String { match self.text_output { - Ok(ref s) => s.clone(), + Ok(ref output) => { + let mut buf = String::new(); + for stage in ["tokens", "parse_trace", "ast", "symbol_table", "type_check"].iter() { + if let Some(artifact) = self.artifacts.get(&stage.to_string()) { + let color = artifact.text_color; + let stage = stage.color(color).bold(); + let output = artifact.debug_output.color(color); + write!(&mut buf, "{}: {}\n", stage, output); + } + } + write!(&mut buf, "{}", output); + buf + } Err(ref s) => format!("{} {}", "Error: ".red().bold(), s) } } diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index 17f32c9..ffe9e22 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -6,10 +6,6 @@ extern crate getopts; extern crate rustyline; extern crate itertools; -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate maplit; #[macro_use] extern crate serde_derive; extern crate serde_json;