From efe65edfe669e29c3ccb2cb75c58c3a12e7b9f49 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 9 Jul 2019 01:32:38 -0700 Subject: [PATCH] Put color into debug output --- schala-repl/src/repl/response.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/schala-repl/src/repl/response.rs b/schala-repl/src/repl/response.rs index d48fc02..b5423fc 100644 --- a/schala-repl/src/repl/response.rs +++ b/schala-repl/src/repl/response.rs @@ -1,5 +1,6 @@ use colored::*; use std::fmt; +use std::fmt::Write; use super::ReplOptions; use crate::language::{ DebugAsk, ComputationResponse}; @@ -12,10 +13,15 @@ pub struct ReplResponse { impl fmt::Display for ReplResponse { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let mut buf = String::new(); 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() + }) } }