From 3b630aa5cf2fd58b10bb8a24c9818fda1d5049af Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 3 Aug 2019 14:18:06 +0800 Subject: Highlight constants --- src/readline/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/readline') diff --git a/src/readline/mod.rs b/src/readline/mod.rs index 97f03bd..e9d4b33 100644 --- a/src/readline/mod.rs +++ b/src/readline/mod.rs @@ -26,6 +26,7 @@ impl Highlighter for LineHighlighter { let op = eval_math_expression(line, 0f64); match op { Ok(_) => { + let constants = ["e", "pi"]; let functions = [ "sin" , "cos" , "tan" , "csc" , "sec" , "cot" , @@ -39,9 +40,11 @@ impl Highlighter for LineHighlighter { let ops = Regex::new(r"(?P[\+-/\*%\^!])").unwrap(); let mut coloured: String = ops.replace_all(line, "\x1b[33m$o\x1b[0m").into(); - for &f in functions.iter() { - let hfn = format!("\x1b[34m{}\x1b[0m", f); - coloured = coloured.replace(f, &hfn[..]); + for c in &constants { + coloured = coloured.replace(c, &format!("\x1b[33m{}\x1b[0m", c)); + } + for f in &functions { + coloured = coloured.replace(f, &format!("\x1b[34m{}\x1b[0m", f)); } Owned(coloured.into()) }, -- cgit v1.2.3