From acf947b608db99ff2e46a8020b6e70466c233088 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 26 Dec 2021 15:27:41 +0100 Subject: Fix highlighting of `e` vs `exp` --- src/readline.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/readline.rs b/src/readline.rs index f59cd22..9912af6 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -62,10 +62,12 @@ impl Highlighter for LineHighlighter { let mut coloured: String = ops.replace_all(line, "\x1b[35m$o\x1b[0m").into(); for c in &constants { - coloured = coloured.replace(c, &format!("\x1b[33m{}\x1b[0m", c)); + let re = Regex::new(format!("(?P{})(?P(\x1b\\[35m)?([\\+-/\\*%\\^! ]|$))", c).as_str()).unwrap(); + coloured = re.replace_all(&coloured, "\x1b[33m$o\x1b[0m$r").into(); } for f in &functions { - coloured = coloured.replace(f, &format!("\x1b[34m{}\x1b[0m", f)); + let re = Regex::new(format!("(?P{})(?P(\\(|$))", f).as_str()).unwrap(); + coloured = re.replace_all(&coloured, "\x1b[34m$o\x1b[0m$r").into(); } Owned(coloured) } -- cgit v1.2.3