feat(tui): add syntax highlighting for code panes using syntect and a new highlight module
This commit is contained in:
@@ -12,6 +12,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
use crate::chat_app::{ChatApp, HELP_TAB_COUNT, MessageRenderContext, ModelSelectorItemKind};
|
||||
use crate::highlight;
|
||||
use crate::state::{
|
||||
CodePane, EditorTab, FileFilterMode, FileNode, LayoutNode, PaletteGroup, PaneId,
|
||||
RepoSearchRowKind, SplitAxis, VisibleFileEntry,
|
||||
@@ -2338,6 +2339,8 @@ fn render_code_pane(
|
||||
.add_modifier(Modifier::ITALIC),
|
||||
)));
|
||||
} else {
|
||||
let mut highlighter =
|
||||
highlight::build_highlighter(pane.absolute_path(), pane.display_path());
|
||||
for (idx, content) in pane.lines.iter().enumerate() {
|
||||
let number = format!("{:>4} ", idx + 1);
|
||||
let mut spans = vec![Span::styled(
|
||||
@@ -2347,12 +2350,22 @@ fn render_code_pane(
|
||||
.add_modifier(Modifier::DIM),
|
||||
)];
|
||||
|
||||
let mut line_style = Style::default().fg(theme.text);
|
||||
if !is_active {
|
||||
line_style = line_style.add_modifier(Modifier::DIM);
|
||||
let segments = highlight::highlight_line(&mut highlighter, content);
|
||||
if segments.is_empty() {
|
||||
let mut line_style = Style::default().fg(theme.text);
|
||||
if !is_active {
|
||||
line_style = line_style.add_modifier(Modifier::DIM);
|
||||
}
|
||||
spans.push(Span::styled(content.clone(), line_style));
|
||||
} else {
|
||||
for (segment_style, text) in segments {
|
||||
let mut style = segment_style;
|
||||
if !is_active {
|
||||
style = style.add_modifier(Modifier::DIM);
|
||||
}
|
||||
spans.push(Span::styled(text, style));
|
||||
}
|
||||
}
|
||||
|
||||
spans.push(Span::styled(content.clone(), line_style));
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user