MCPcopy Create free account
hub / github.com/csskit/csskit / render_text

Method render_text

crates/csskit/src/commands/find.rs:176–196  ·  view source on GitHub ↗
(&self, ctx: &TokenHighlighter, _file: &str, src: &str, span: Span, _row: &FindData, color: bool)

Source from the content-addressed store, hash-verified

174 }
175
176 fn render_text(&self, ctx: &TokenHighlighter, _file: &str, src: &str, span: Span, _row: &FindData, color: bool) {
177 let (line, col) = span.line_and_column(src);
178 let (start, end) = line_bounds(src, span.start().into());
179
180 if color {
181 print!("{}:{}:", green(line + 1), green(col + 1));
182 let line_text = &src[start..end];
183 let line_lexer = Lexer::new(&CssAtomSet::ATOMS, line_text);
184 let mut line_output = String::new();
185 let mut cursor_stream = AnsiHighlightCursorStream::new(&mut line_output, ctx, DefaultAnsiTheme);
186 for cursor in line_lexer {
187 let global_offset = SourceOffset(cursor.offset().0 + start as u32);
188 let global_cursor = Cursor::new(global_offset, cursor.token());
189 let sc = SourceCursor::from(global_cursor, cursor.str_slice(line_text));
190 cursor_stream.append(sc);
191 }
192 println!("{}", line_output);
193 } else {
194 println!("{}:{}:{}", line + 1, col + 1, &src[start..end]);
195 }
196 }
197}

Callers 1

runMethod · 0.45

Calls 8

line_boundsFunction · 0.85
SourceOffsetClass · 0.85
line_and_columnMethod · 0.80
str_sliceMethod · 0.80
startMethod · 0.45
offsetMethod · 0.45
tokenMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected