manen

Fancy Lua REPL
Log | Files | Refs | README | LICENSE

commit e656936cf80ad19b0fce27ca114428f6202fe58e
parent 06138d63030e17c2347ebea0958c5c4b650491e8
Author: Sylvia Ivory <git@sivory.net>
Date:   Sun, 22 Jun 2025 20:36:33 -0700

Fix string escape code highlighting

Diffstat:
Msrc/highlight.rs | 8+++++++-
Msrc/inspect.rs | 11+++++++----
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/highlight.rs b/src/highlight.rs @@ -126,14 +126,20 @@ impl reedline::Highlighter for LuaHighlighter { }; let mut style = Style::new(); + let mut highlight = 0usize; for event in highlights.flatten() { match event { HighlightEvent::Source { start, end } => { - text.push((style, line[start..end].to_string())) + text.push((style, line[start..end].to_string())); + + if highlight == 18 { + style = STYLES[17]; + } } HighlightEvent::HighlightStart(s) => { style = STYLES[s.0]; + highlight = s.0; } HighlightEvent::HighlightEnd => {} } diff --git a/src/inspect.rs b/src/inspect.rs @@ -14,6 +14,7 @@ lazy_static! { String::from("\t"), String::from("\x0B"), String::from("\x7F"), + String::from("\\"), ]; let mut replacements = vec![ @@ -25,6 +26,7 @@ lazy_static! { String::from("\\t"), String::from("\\v"), String::from("\\127"), + String::from("\\\\"), ]; for i in 0..=31 { @@ -38,7 +40,7 @@ lazy_static! { static ref REPLACEMENT_COLOR: Vec<String> = AC_REPLACEMENTS .1 .iter() - .map(|s| Color::Cyan.paint(s).to_string()) + .map(|s| format!("{}{}", Color::Cyan.paint(s), Color::Green.prefix())) .collect(); } @@ -49,9 +51,10 @@ fn escape_control(s: &str) -> String { } fn escape_control_color(s: &str) -> String { - ESCAPER - .replace_all(s, &REPLACEMENT_COLOR) - .replace("\\\\x", &Color::Cyan.paint("\\x").to_string()) + ESCAPER.replace_all(s, &REPLACEMENT_COLOR).replace( + "\\\\x", + &format!("{}{}", Color::Cyan.paint("\\x"), Color::Green.prefix()), + ) } fn remove_invalid(mut bytes: &[u8]) -> String {