aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/readline.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/readline.rs b/src/readline.rs
index 9912af6..6734674 100644
--- a/src/readline.rs
+++ b/src/readline.rs
@@ -15,6 +15,7 @@ use regex::Regex;
15 15
16use crate::error::CalcError; 16use crate::error::CalcError;
17use crate::eval_math_expression; 17use crate::eval_math_expression;
18use crate::lex::{CONSTANTS, FUNCTIONS};
18 19
19pub struct RLHelper { 20pub struct RLHelper {
20 completer: FilenameCompleter, 21 completer: FilenameCompleter,
@@ -52,20 +53,16 @@ impl Highlighter for LineHighlighter {
52 let op = eval_math_expression(line, prev_ans); 53 let op = eval_math_expression(line, prev_ans);
53 match op { 54 match op {
54 Ok(_) => { 55 Ok(_) => {
55 let constants = ["e", "pi"]; 56 let constants = CONSTANTS.keys();
56 let functions = [ 57 let functions = FUNCTIONS.keys();
57 "sin", "cos", "tan", "csc", "sec", "cot", "sinh", "cosh", "tanh", "ln", "log",
58 "sqrt", "ceil", "floor", "rad", "deg", "abs", "asin", "acos", "atan", "acsc",
59 "asec", "acot", "exp2", "exp"
60 ];
61 let ops = Regex::new(r"(?P<o>[\+-/\*%\^!])").unwrap(); 58 let ops = Regex::new(r"(?P<o>[\+-/\*%\^!])").unwrap();
62 let mut coloured: String = ops.replace_all(line, "\x1b[35m$o\x1b[0m").into(); 59 let mut coloured: String = ops.replace_all(line, "\x1b[35m$o\x1b[0m").into();
63 60
64 for c in &constants { 61 for c in constants {
65 let re = Regex::new(format!("(?P<o>{})(?P<r>(\x1b\\[35m)?([\\+-/\\*%\\^! ]|$))", c).as_str()).unwrap(); 62 let re = Regex::new(format!("(?P<o>{})(?P<r>(\x1b\\[35m)?([\\+-/\\*%\\^! ]|$))", c).as_str()).unwrap();
66 coloured = re.replace_all(&coloured, "\x1b[33m$o\x1b[0m$r").into(); 63 coloured = re.replace_all(&coloured, "\x1b[33m$o\x1b[0m$r").into();
67 } 64 }
68 for f in &functions { 65 for f in functions {
69 let re = Regex::new(format!("(?P<o>{})(?P<r>(\\(|$))", f).as_str()).unwrap(); 66 let re = Regex::new(format!("(?P<o>{})(?P<r>(\\(|$))", f).as_str()).unwrap();
70 coloured = re.replace_all(&coloured, "\x1b[34m$o\x1b[0m$r").into(); 67 coloured = re.replace_all(&coloured, "\x1b[34m$o\x1b[0m$r").into();
71 } 68 }