diff --git a/src/filetype.rs b/src/filetype.rs index fc0e3a9..9e0a21d 100644 --- a/src/filetype.rs +++ b/src/filetype.rs @@ -8,6 +8,7 @@ pub struct HighlightingOptions { numbers: bool, strings: bool, characters: bool, + comments: bool, } impl Default for FileType { @@ -36,6 +37,7 @@ impl FileType { numbers: true, strings: true, characters: true, + comments: true, }, }; } @@ -56,4 +58,8 @@ impl HighlightingOptions { pub fn characters(self) -> bool { self.characters } + + pub fn comments(self) -> bool { + self.comments + } } \ No newline at end of file diff --git a/src/highlighting.rs b/src/highlighting.rs index a137531..2d2921d 100644 --- a/src/highlighting.rs +++ b/src/highlighting.rs @@ -7,6 +7,7 @@ pub enum Type { Match, String, Character, + Comment, } impl Type { @@ -16,6 +17,7 @@ impl Type { Type::Match => color::Rgb(38, 139, 210), Type::String => color::Rgb(211, 54, 130), Type::Character => color::Rgb(108, 113, 196), + Type::Comment => color::Rgb(133, 153, 0), _ => color::Rgb(255, 255, 255), } } diff --git a/src/row.rs b/src/row.rs index 527b9e0..aa7e2a8 100644 --- a/src/row.rs +++ b/src/row.rs @@ -289,6 +289,18 @@ impl Row { } } + if opts.comments() && *c == '/' { + if let Some(next_char) = chars.get(index.saturating_add(1)) { + if *next_char == '/' { + for _ in index..chars.len() { + highlighting.push(highlighting::Type::Comment); + } + + break; + } + }; + } + if opts.numbers() { if (c.is_ascii_digit() && (prev_is_separator || *previous_highlight == highlighting::Type::Number))