@@ -20,6 +20,7 @@ use crate::git_config::{GitConfig, GitConfigEntry};
2020use crate :: minusplus:: MinusPlus ;
2121use crate :: paint:: BgFillMethod ;
2222use crate :: parse_styles;
23+ use crate :: style;
2324use crate :: style:: Style ;
2425use crate :: tests:: TESTING ;
2526use crate :: utils:: bat:: output:: PagingMode ;
@@ -105,6 +106,7 @@ pub struct Config {
105106 pub line_numbers_style_minusplus : MinusPlus < Style > ,
106107 pub line_numbers_zero_style : Style ,
107108 pub line_numbers : bool ,
109+ pub styles_map : Option < HashMap < style:: AnsiTermStyleEqualityKey , Style > > ,
108110 pub max_line_distance_for_naively_paired_lines : f64 ,
109111 pub max_line_distance : f64 ,
110112 pub max_line_length : usize ,
@@ -157,6 +159,7 @@ impl Config {
157159impl From < cli:: Opt > for Config {
158160 fn from ( opt : cli:: Opt ) -> Self {
159161 let styles = parse_styles:: parse_styles ( & opt) ;
162+ let styles_map = make_styles_map ( & opt) ;
160163
161164 let max_line_distance_for_naively_paired_lines =
162165 env:: get_env_var ( "DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES" )
@@ -297,6 +300,7 @@ impl From<cli::Opt> for Config {
297300 ) ,
298301 line_numbers_zero_style : styles[ "line-numbers-zero-style" ] ,
299302 line_buffer_size : opt. line_buffer_size ,
303+ styles_map,
300304 max_line_distance : opt. max_line_distance ,
301305 max_line_distance_for_naively_paired_lines,
302306 max_line_length : match ( opt. side_by_side , wrap_max_lines_plus1) {
@@ -396,6 +400,28 @@ fn make_blame_palette(blame_palette: Option<String>, is_light_mode: bool) -> Vec
396400 }
397401}
398402
403+ fn make_styles_map ( opt : & cli:: Opt ) -> Option < HashMap < style:: AnsiTermStyleEqualityKey , Style > > {
404+ if let Some ( styles_map_str) = & opt. map_styles {
405+ let mut styles_map = HashMap :: new ( ) ;
406+ for pair_str in styles_map_str. split ( ',' ) {
407+ let mut style_strs = pair_str. split ( "=>" ) . map ( |s| s. trim ( ) ) ;
408+ if let ( Some ( from_str) , Some ( to_str) ) = ( style_strs. next ( ) , style_strs. next ( ) ) {
409+ let key = style:: ansi_term_style_equality_key (
410+ Style :: from_str ( from_str, None , None , true , opt. git_config . as_ref ( ) )
411+ . ansi_term_style ,
412+ ) ;
413+ styles_map. insert (
414+ key,
415+ Style :: from_str ( to_str, None , None , true , opt. git_config . as_ref ( ) ) ,
416+ ) ;
417+ }
418+ }
419+ Some ( styles_map)
420+ } else {
421+ None
422+ }
423+ }
424+
399425/// Did the user supply `option` on the command line?
400426pub fn user_supplied_option ( option : & str , arg_matches : & clap:: ArgMatches ) -> bool {
401427 arg_matches. occurrences_of ( option) > 0
0 commit comments