aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Tham <[email protected]>2019-08-03 07:18:06 +0100
committerIvan Tham <[email protected]>2019-08-03 07:18:06 +0100
commit3b630aa5cf2fd58b10bb8a24c9818fda1d5049af (patch)
treee9ad993d5e1808b06212a755af691855f54e70f3 /src
parent96db39bad36d0554ca5a48d6bc294e7aae6b2df6 (diff)
Highlight constants
Diffstat (limited to 'src')
-rw-r--r--src/readline/mod.rs9
1 files changed, 6 insertions, 3 deletions
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 {
26 let op = eval_math_expression(line, 0f64); 26 let op = eval_math_expression(line, 0f64);
27 match op { 27 match op {
28 Ok(_) => { 28 Ok(_) => {
29 let constants = ["e", "pi"];
29 let functions = [ 30 let functions = [
30 "sin" , "cos" , "tan" , 31 "sin" , "cos" , "tan" ,
31 "csc" , "sec" , "cot" , 32 "csc" , "sec" , "cot" ,
@@ -39,9 +40,11 @@ impl Highlighter for LineHighlighter {
39 let ops = Regex::new(r"(?P<o>[\+-/\*%\^!])").unwrap(); 40 let ops = Regex::new(r"(?P<o>[\+-/\*%\^!])").unwrap();
40 let mut coloured: String = ops.replace_all(line, "\x1b[33m$o\x1b[0m").into(); 41 let mut coloured: String = ops.replace_all(line, "\x1b[33m$o\x1b[0m").into();
41 42
42 for &f in functions.iter() { 43 for c in &constants {
43 let hfn = format!("\x1b[34m{}\x1b[0m", f); 44 coloured = coloured.replace(c, &format!("\x1b[33m{}\x1b[0m", c));
44 coloured = coloured.replace(f, &hfn[..]); 45 }
46 for f in &functions {
47 coloured = coloured.replace(f, &format!("\x1b[34m{}\x1b[0m", f));
45 } 48 }
46 Owned(coloured.into()) 49 Owned(coloured.into())
47 }, 50 },