@@ -27,7 +27,8 @@ use std::fmt::Write;
2727use supports_unicode:: supports_unicode;
2828
2929fn main ( ) -> Result < ( ) , FetchInfoError > {
30- let config: Config = load_config ( ) ;
30+ let mut config_buffer: Vec < u8 > = Vec :: new ( ) ;
31+ let config: Config = load_config ( & mut config_buffer) ;
3132 let language_func = get_language ( config. language ) ;
3233
3334 let results: HashMap < InfoKind , Result < InfoResult , FetchInfoError > > = config
@@ -55,17 +56,20 @@ fn main() -> Result<(), FetchInfoError> {
5556 } )
5657 . collect ( ) ;
5758
58- let logo = if supports_unicode ( ) {
59+ let logo_buffer;
60+ let mut logo = if supports_unicode ( ) {
5961 match config. logo {
60- LogoStyle :: Braille { logo } => Some ( get_logo ( logo. map ( str:: to_owned) ) ) ,
62+ LogoStyle :: Braille { logo } => Some ( get_logo ( logo. map ( str:: to_owned) ) )
63+ . map ( |( max_length, ansi, logo) | ( max_length, ansi, logo. lines ( ) ) ) ,
6164 LogoStyle :: File { location : path } => {
62- let file_content: & str = Box :: leak ( std:: fs:: read_to_string ( path) ?. into_boxed_str ( ) ) ;
63- let max_length = count_str_length ( file_content) + 6 ;
64- Some ( ( max_length, 0 , file_content) )
65+ logo_buffer = Some ( std:: fs:: read_to_string ( path) ?) ;
66+ logo_buffer. as_deref ( ) . map ( |logo| {
67+ let max_length = count_str_length ( logo) + 6 ;
68+ ( max_length, 0 , logo. lines ( ) )
69+ } )
6570 }
6671 _ => None ,
6772 }
68- . map ( |( max_length, ansi, logo) | ( max_length, ansi, logo. lines ( ) . collect :: < Vec < & str > > ( ) ) )
6973 } else {
7074 None
7175 } ;
@@ -105,7 +109,6 @@ fn main() -> Result<(), FetchInfoError> {
105109
106110 let mut output: String = String :: default ( ) ;
107111 let mut last_info_len = 0 ;
108- let mut i = 0 ;
109112
110113 for entry in & config. entries {
111114 let mut write_entry = |entry : String | {
@@ -114,20 +117,18 @@ fn main() -> Result<(), FetchInfoError> {
114117 writeln ! ( output, "{}{}" , " " . repeat( 47 ) , entry) . ok ( ) ;
115118 }
116119
117- if let Some ( ( logo_width , _, lines) ) = & logo {
118- if lines . len ( ) > i {
119- writeln ! ( output, " {}{} {}" , lines [ i ] , "" . white( ) , entry) . ok ( ) ;
120+ if let Some ( ( width , _, lines) ) = logo. as_mut ( ) {
121+ if let Some ( line ) = lines . next ( ) {
122+ writeln ! ( output, " {}{} {}" , line , "" . white( ) , entry) . ok ( ) ;
120123 } else {
121- writeln ! ( output, "{}{}" , " " . repeat( * logo_width ) , entry) . ok ( ) ;
124+ writeln ! ( output, "{}{}" , " " . repeat( * width ) , entry) . ok ( ) ;
122125 }
123126 }
124127
125128 #[ cfg( not( feature = "image" ) ) ]
126129 if logo. is_none ( ) {
127130 writeln ! ( output, "{entry}" ) . ok ( ) ;
128131 }
129-
130- i += 1 ;
131132 } ;
132133
133134 match entry {
@@ -208,11 +209,9 @@ fn main() -> Result<(), FetchInfoError> {
208209 }
209210 }
210211
211- if let Some ( ( _, _, lines) ) = & logo
212- && i < lines. len ( )
213- {
214- for logo_line in & lines[ i..] {
215- writeln ! ( output, " {}{}" , logo_line, "" . white( ) ) . ok ( ) ;
212+ if let Some ( ( _, _, lines) ) = logo {
213+ for line in lines {
214+ writeln ! ( output, " {}{}" , line, "" . white( ) ) . ok ( ) ;
216215 }
217216 }
218217
0 commit comments