diff --git a/src/filetype.rs b/src/filetype.rs index b05ce9c..fc0e3a9 100644 --- a/src/filetype.rs +++ b/src/filetype.rs @@ -7,6 +7,7 @@ pub struct FileType { pub struct HighlightingOptions { numbers: bool, strings: bool, + characters: bool, } impl Default for FileType { @@ -34,6 +35,7 @@ impl FileType { hl_opts: HighlightingOptions { numbers: true, strings: true, + characters: true, }, }; } @@ -50,4 +52,8 @@ impl HighlightingOptions { pub fn strings(self) -> bool { self.strings } + + pub fn characters(self) -> bool { + self.characters + } } \ No newline at end of file diff --git a/src/highlighting.rs b/src/highlighting.rs index f34cb52..a137531 100644 --- a/src/highlighting.rs +++ b/src/highlighting.rs @@ -6,6 +6,7 @@ pub enum Type { Number, Match, String, + Character, } impl Type { @@ -14,6 +15,7 @@ impl Type { Type::Number => color::Rgb(220, 163, 163), Type::Match => color::Rgb(38, 139, 210), Type::String => color::Rgb(211, 54, 130), + Type::Character => color::Rgb(108, 113, 196), _ => color::Rgb(255, 255, 255), } } diff --git a/src/row.rs b/src/row.rs index 57da1cb..527b9e0 100644 --- a/src/row.rs +++ b/src/row.rs @@ -232,6 +232,33 @@ impl Row { &highlighting::Type::None }; + if opts.characters() && !in_string && *c == '\'' { + prev_is_separator = true; + + if let Some(next_char) = chars.get(index.saturating_add(1)) { + let closing_index = if *next_char == '\\' { + index.saturating_add(3) + } else { + index.saturating_add(2) + }; + + if let Some(closing_char) = chars.get(closing_index) { + if *closing_char == '\'' { + for _ in 0..=closing_index.saturating_sub(index) { + highlighting.push(highlighting::Type::Character); + index += 1; + } + + continue; + } + } + } + + highlighting.push(highlighting::Type::None); + index += 1; + continue; + } + if opts.strings() { if in_string { highlighting.push(highlighting::Type::String);