@@ -84,8 +84,13 @@ fn get_syntax_definition(language: Option<&str>) -> &'static syntect::parsing::S
84
84
}
85
85
86
86
#[ cfg( feature = "syntax-highlighting" ) ]
87
- fn syntect_to_ratatui_color ( _color : SyntectColor ) -> Option < Color > {
88
- // Use ANSI colors instead of RGB for better terminal compatibility
87
+ fn syntect_to_ratatui_color ( color : SyntectColor ) -> Option < Color > {
88
+ if color. a == 0 {
89
+ // Transparent color, skip it
90
+ return None ;
91
+ }
92
+
93
+ // Use ANSI colors instead of RGB
89
94
None
90
95
}
91
96
@@ -351,12 +356,13 @@ where
351
356
let ranges: Vec < ( syntect:: highlighting:: Style , & str ) > = highlighter
352
357
. highlight_line ( line, & SYNTAX_SET )
353
358
. unwrap_or_else ( |_| vec ! [ ( syntect:: highlighting:: Style :: default ( ) , line) ] ) ;
359
+
354
360
let spans: Vec < Span > = ranges
355
361
. into_iter ( )
356
362
. map ( |( syn_style, text) | {
357
363
let fg = syn_style. foreground ;
358
- let mut style = Style :: default ( )
359
- . fg ( syntect_to_ratatui_color ( fg ) . unwrap_or ( Color :: Reset ) ) ;
364
+ let color = syntect_to_ratatui_color ( fg ) ;
365
+ let mut style = Style :: default ( ) . fg ( color . unwrap_or ( Color :: Reset ) ) ;
360
366
if let Some ( bg_color) = syntect_to_ratatui_color ( syn_style. background ) {
361
367
style = style. bg ( bg_color) ;
362
368
} else {
@@ -372,10 +378,6 @@ where
372
378
// No syntax highlighting, just push the line as is
373
379
self . push_line ( Line :: from ( line. to_string ( ) ) ) ;
374
380
}
375
- if !highlighted {
376
- // No syntax highlighting, just push the line as is
377
- self . push_line ( Line :: from ( line. to_string ( ) ) ) ;
378
- }
379
381
} else {
380
382
let mut content = line. to_string ( ) ;
381
383
if let ( Some ( scheme) , Some ( cwd) ) = ( & self . scheme , & self . cwd ) {
@@ -506,21 +508,19 @@ where
506
508
self . current_code_lang = _lang. clone ( ) ;
507
509
if let Some ( lang) = & _lang {
508
510
let syntax = get_syntax_definition ( Some ( lang) ) ;
509
- let theme = match self
511
+ let theme = self
510
512
. syntax_highlight_theme
511
513
. as_ref ( )
512
514
. and_then ( |t| THEME . themes . get ( t) )
513
515
. or_else ( || THEME . themes . get ( "base16-ocean.dark" ) )
514
516
. or_else ( || THEME . themes . get ( "InspiredGitHub" ) )
515
- . or_else ( || THEME . themes . values ( ) . next ( ) )
516
- {
517
- Some ( t) => t,
518
- None => {
519
- self . current_highlighter = None ;
520
- return ;
521
- }
522
- } ;
523
- self . current_highlighter = Some ( HighlightLines :: new ( syntax, theme) ) ;
517
+ . or_else ( || THEME . themes . values ( ) . next ( ) ) ;
518
+
519
+ if let Some ( t) = theme {
520
+ self . current_highlighter = Some ( HighlightLines :: new ( syntax, t) ) ;
521
+ } else {
522
+ self . current_highlighter = None ;
523
+ }
524
524
} else {
525
525
self . current_highlighter = None ;
526
526
}
0 commit comments