1- use crate :: config:: { conf_unwrap_or, schema:: Alignment } ;
1+ use std:: { env, io:: stdin} ;
2+
3+ use crate :: {
4+ config:: {
5+ conf_unwrap_or,
6+ default:: ASCII_TUX ,
7+ schema:: { Alignment , Color } ,
8+ } ,
9+ util:: { format_ascii_art, get_fmt_line_len} ,
10+ } ;
211
312mod config;
413mod modules;
14+ mod util;
515
616fn main ( ) {
717 let config = config:: read ( ) ;
818
9- let ascii_art = config. theme . get_formatted_ascii_art ( ) ;
19+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
20+
21+ let ascii_art = if args. len ( ) > 1 && args. contains ( & "--stdin" . to_string ( ) ) {
22+ let mut buf = String :: new ( ) ;
23+ loop {
24+ let bytes = stdin ( )
25+ . read_line ( & mut buf)
26+ . expect ( "Couldn't read from stdin" ) ;
27+ if bytes == 0 {
28+ break ;
29+ }
30+ }
31+ buf
32+ } else {
33+ conf_unwrap_or ! ( config, ASCII_TUX . to_owned( ) , theme / ascii_art) . to_owned ( )
34+ } ;
35+ let ascii_art = format_ascii_art ( ascii_art) ;
36+
1037 let modules = modules:: get_modules ( & config) ;
1138
1239 let mut lines = vec ! [ ] ;
1340
1441 for line in ascii_art. lines ( ) {
15- if let Some ( color) = & config. theme . art_color {
16- lines. push ( format ! ( "\x1b [{}m {line}\x1b [0m" , color. to_owned( ) as u32 ) )
17- } else {
18- lines. push ( format ! ( " {line}" ) )
19- }
42+ let color = conf_unwrap_or ! ( config, Color :: Reset , theme / art_color) ;
43+ lines. push ( format ! ( "\x1b [{}m {line}\x1b [0m" , color. to_owned( ) as u32 ) ) ;
2044 }
2145
2246 let modules_start = match conf_unwrap_or ! ( config, Alignment :: Top , modules / alignment) {
@@ -30,12 +54,19 @@ fn main() {
3054 }
3155 } ;
3256
57+ let longest_art_line = get_fmt_line_len ( lines. first ( ) . unwrap_or ( & "" . to_string ( ) ) ) ;
3358 for i in 0 ..modules. len ( ) {
59+ let spacing = conf_unwrap_or ! ( config, 2 , theme / art_info_spacing) ;
60+
3461 match lines. get_mut ( i + modules_start) {
35- Some ( line) => line. push_str ( & format ! ( " {}" , modules. get( i) . unwrap( ) ) ) ,
62+ Some ( line) => line. push_str ( & format ! (
63+ "{}{}" ,
64+ " " . repeat( spacing) ,
65+ modules. get( i) . unwrap( )
66+ ) ) ,
3667 None => lines. push ( format ! (
37- " {}{}" ,
38- " " . repeat( config . theme . get_fmt_art_longest_ln ( ) ) ,
68+ "{}{}" ,
69+ " " . repeat( spacing + longest_art_line ) ,
3970 modules. get( i) . unwrap( )
4071 ) ) ,
4172 }
0 commit comments