@@ -16,29 +16,6 @@ impl<'a> Coloring<'a> {
1616 pub fn new ( ls_colors : LsColors , map : HashMap < Vec < & ' a OsStr > , Color > ) -> Self {
1717 Coloring { ls_colors, map }
1818 }
19-
20- /// Look up the color for a node identified by its path components and whether it has children,
21- /// then wrap the given [`TreeHorizontalSlice`] in the appropriate colored or colorless variant.
22- fn maybe_colored_tree_slice (
23- & self ,
24- path_components : & [ & ' a OsStr ] ,
25- has_children : bool ,
26- slice : TreeHorizontalSlice < String > ,
27- ) -> MaybeColoredTreeHorizontalSlice < ' _ > {
28- let color = if has_children {
29- Some ( Color :: Directory )
30- } else {
31- self . map . get ( path_components) . copied ( )
32- } ;
33- match color {
34- Some ( color) => MaybeColoredTreeHorizontalSlice :: Colorful ( ColoredTreeHorizontalSlice {
35- slice,
36- color,
37- ls_colors : & self . ls_colors ,
38- } ) ,
39- None => MaybeColoredTreeHorizontalSlice :: Colorless ( slice) ,
40- }
41- }
4219}
4320
4421/// The coloring to apply to a node name.
@@ -120,11 +97,22 @@ pub(super) fn maybe_colored_slice<'a, 'b>(
12097 has_children : bool ,
12198 slice : TreeHorizontalSlice < String > ,
12299) -> MaybeColoredTreeHorizontalSlice < ' b > {
123- match coloring {
124- Some ( coloring) => {
125- let path_components: Vec < & OsStr > = ancestors. chain ( std:: iter:: once ( name) ) . collect ( ) ;
126- coloring. maybe_colored_tree_slice ( & path_components, has_children, slice)
127- }
100+ let coloring = match coloring {
101+ Some ( coloring) => coloring,
102+ None => return MaybeColoredTreeHorizontalSlice :: Colorless ( slice) ,
103+ } ;
104+ let path_components: Vec < & OsStr > = ancestors. chain ( std:: iter:: once ( name) ) . collect ( ) ;
105+ let color = if has_children {
106+ Some ( Color :: Directory )
107+ } else {
108+ coloring. map . get ( & path_components) . copied ( )
109+ } ;
110+ match color {
111+ Some ( color) => MaybeColoredTreeHorizontalSlice :: Colorful ( ColoredTreeHorizontalSlice {
112+ slice,
113+ color,
114+ ls_colors : & coloring. ls_colors ,
115+ } ) ,
128116 None => MaybeColoredTreeHorizontalSlice :: Colorless ( slice) ,
129117 }
130118}
0 commit comments