MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / highlight

Method highlight

src/gitql/gitql_line_editor.rs:128–179  ·  view source on GitHub ↗
(&self, buffer: &mut StyledBuffer)

Source from the content-addressed store, hash-verified

126
127impl Highlighter for GitQLHighlighter {
128 fn highlight(&self, buffer: &mut StyledBuffer) {
129 let lines = buffer.buffer().clone();
130 let mut i: usize = 0;
131
132 let mut keyword_style = Style::default();
133 keyword_style.set_foreground_color(Color::Magenta);
134
135 let mut string_style = Style::default();
136 string_style.set_foreground_color(Color::Yellow);
137
138 loop {
139 if i >= lines.len() {
140 break;
141 }
142
143 // Highlight String literal
144 if lines[i] == '"' {
145 buffer.style_char(i, string_style.clone());
146 i += 1;
147
148 while i < lines.len() && lines[i] != '"' {
149 buffer.style_char(i, string_style.clone());
150 i += 1;
151 }
152
153 if i < lines.len() && lines[i] == '"' {
154 buffer.style_char(i, string_style.clone());
155 i += 1;
156 }
157
158 continue;
159 }
160
161 // Highlight reserved keyword
162 if lines[i].is_alphabetic() {
163 let start = i;
164 let mut keyword = String::new();
165 while i < lines.len() && (lines[i].is_alphanumeric() || lines[i] == '_') {
166 keyword.push(lines[i]);
167 i += 1;
168 }
169
170 keyword = keyword.to_lowercase();
171 if GITQL_RESERVED_KEYWORDS.contains(&keyword.as_str()) {
172 buffer.style_range(start, i, keyword_style.clone())
173 }
174 continue;
175 }
176
177 i += 1;
178 }
179 }
180}
181
182#[derive(Default)]

Callers

nothing calls this directly

Calls 3

containsMethod · 0.80
lenMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected