-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.rs
More file actions
62 lines (61 loc) · 2.29 KB
/
Copy pathsyntax.rs
File metadata and controls
62 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! # Syntax Highlighting Module
//!
//! This module provides syntax highlighting functionality for displaying diffs with
//! colored syntax-aware output. It integrates with the Syntect library for language
//! detection and highlighting, and uses Ratatui for terminal display.
//!
//! ## Overview
//!
//! The syntax module enables the application to display code with proper syntax highlighting
//! in the terminal UI. It intelligently colors different parts of code based on the programming
//! language being displayed, making diffs easier to read and understand.
//!
//! ## Components
//!
//! - **highlighter**: Handles the actual syntax highlighting of individual lines using
//! Syntect for language-aware coloring
//!
//! ## Features
//!
//! - **Language Detection**: Automatically detects the programming language based on file extension
//! - **Syntax-Aware Coloring**: Uses theme-aware syntax highlighting to color code appropriately
//! - **Diff Integration**: Combines syntax highlighting with diff-specific colors (red for deletions,
//! green for additions)
//! - **Terminal-Ready**: Converts highlighting information to Ratatui styles for terminal display
//!
//! ## Usage Example
//!
//! ```ignore
//! use syntax::highlighter;
//! use crate::ui::app::App;
//! use ratatui::style::Color;
//!
//! // Highlight a line of code with syntax highlighting
//! let app = App::new();
//! let syntax = app.syntax_set.find_syntax_by_extension("rs")?;
//! let styled_spans = highlighter::highlight_line_content(
//! "fn main() { println!(\"Hello\"); }",
//! syntax,
//! &app,
//! Color::Reset,
//! );
//!
//! // Use the styled spans in your UI
//! for span in styled_spans {
//! // Display span with its styling...
//! }
//! ```
//!
//! ## Themes and Styling
//!
//! The module respects the theme configured in the application. Different themes
//! (like Solarized, Monokai, etc.) will produce different color outputs, providing
//! a consistent look with the overall application theme.
//!
//! ## Integration with Diffs
//!
//! When highlighting diff content, the module automatically:
//! - Applies red coloring and dark red background for deleted lines
//! - Applies green coloring and dark green background for added lines
//! - Maintains syntax highlighting within the diff-specific colors
pub mod highlighter;