diff --git a/src/document.rs b/src/document.rs index 2a83bf5..7ba9cb7 100644 --- a/src/document.rs +++ b/src/document.rs @@ -175,8 +175,8 @@ impl Document { let current_row = &mut self.rows[at.y]; let mut new_row = current_row.split(at.x); - current_row.highlight(None); - new_row.highlight(None); + current_row.highlight(self.file_type.highlighting_options(), None); + new_row.highlight(self.file_type.highlighting_options(), None); #[allow(clippy::integer_arithmetic)] self.rows.insert(at.y + 1, new_row); diff --git a/src/filetype.rs b/src/filetype.rs index 8710a6a..b05ce9c 100644 --- a/src/filetype.rs +++ b/src/filetype.rs @@ -6,6 +6,7 @@ pub struct FileType { #[derive(Default, Copy, Clone)] pub struct HighlightingOptions { numbers: bool, + strings: bool, } impl Default for FileType { @@ -30,7 +31,10 @@ impl FileType { if file_name.ends_with(".rs") { return Self { name: String::from("Rust"), - hl_opts: HighlightingOptions { numbers: true }, + hl_opts: HighlightingOptions { + numbers: true, + strings: true, + }, }; } @@ -42,4 +46,8 @@ impl HighlightingOptions { pub fn numbers(self) -> bool { self.numbers } + + pub fn strings(self) -> bool { + self.strings + } } \ No newline at end of file diff --git a/src/highlighting.rs b/src/highlighting.rs index b0e3d31..f34cb52 100644 --- a/src/highlighting.rs +++ b/src/highlighting.rs @@ -5,6 +5,7 @@ pub enum Type { None, Number, Match, + String, } impl Type { @@ -12,6 +13,7 @@ impl Type { match self { Type::Number => color::Rgb(220, 163, 163), Type::Match => color::Rgb(38, 139, 210), + Type::String => color::Rgb(211, 54, 130), _ => color::Rgb(255, 255, 255), } } diff --git a/src/row.rs b/src/row.rs index 5d3f434..3384563 100644 --- a/src/row.rs +++ b/src/row.rs @@ -210,6 +210,7 @@ impl Row { } let mut prev_is_separator = true; + let mut in_string = false; let mut index = 0; while let Some(c) = chars.get(index) { if let Some(word) = word { @@ -231,6 +232,28 @@ impl Row { &highlighting::Type::None }; + if opts.strings() { + if in_string { + highlighting.push(highlighting::Type::String); + if *c == '"' { + in_string = false; + prev_is_separator = true; + } else { + prev_is_separator = false; + } + + index += 1; + continue; + } else if prev_is_separator && *c == '"' { + highlighting.push(highlighting::Type::String); + + in_string = true; + prev_is_separator = true; + index += 1; + continue; + } + } + if opts.numbers() { if (c.is_ascii_digit() && (prev_is_separator || previous_highlight == &highlighting::Type::Number))