Put color into debug output

This commit is contained in:
greg 2019-07-09 01:32:38 -07:00
parent 7c9154de53
commit efe65edfe6
1 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,6 @@
use colored::*; use colored::*;
use std::fmt; use std::fmt;
use std::fmt::Write;
use super::ReplOptions; use super::ReplOptions;
use crate::language::{ DebugAsk, ComputationResponse}; use crate::language::{ DebugAsk, ComputationResponse};
@ -12,10 +13,15 @@ pub struct ReplResponse {
impl fmt::Display for ReplResponse { impl fmt::Display for ReplResponse {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut buf = String::new();
if let Some(ref label) = self.label { if let Some(ref label) = self.label {
write!(f, "({})", label).unwrap(); write!(buf, "({})", label).unwrap();
} }
write!(f, "=> {}", self.text) write!(buf, "=> {}", self.text).unwrap();
write!(f, "{}", match self.color {
Some(c) => buf.color(c),
None => buf.normal()
})
} }
} }