Highlight single-line comments
This commit is contained in:
parent
d84da2b0de
commit
aa849373ad
@ -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
|
||||
}
|
||||
}
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
12
src/row.rs
12
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))
|
||||
|
Loading…
Reference in New Issue
Block a user