@@ -14,12 +14,13 @@ struct Info {
14
14
impl fmt:: Display for Info {
15
15
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
16
16
let mut s = String :: from ( "\n " ) ;
17
- s. push_str ( & ( "Project: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . project_name) ) ) ;
18
- s. push_str ( & ( "Language: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . language) ) ) ;
19
- s. push_str ( & ( "Author: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . author) ) ) ;
20
- s. push_str ( & ( "Repo: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . repo) ) ) ;
21
- s. push_str ( & ( "Number of lines: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . number_of_lines) ) ) ;
22
- s. push_str ( & ( "License: " . blue ( ) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . license) ) ) ;
17
+ let color = get_color ( & self . language ) ;
18
+ s. push_str ( & ( "Project: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . project_name) ) ) ;
19
+ s. push_str ( & ( "Language: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . language) ) ) ;
20
+ s. push_str ( & ( "Author: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . author) ) ) ;
21
+ s. push_str ( & ( "Repo: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . repo) ) ) ;
22
+ s. push_str ( & ( "Number of lines: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . number_of_lines) ) ) ;
23
+ s. push_str ( & ( "License: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . license) ) ) ;
23
24
24
25
let logo= self . get_ascii ( ) ;
25
26
let mut lines = s. lines ( ) ;
@@ -30,7 +31,7 @@ impl fmt::Display for Info {
30
31
Some ( line) => line,
31
32
None => "" ,
32
33
} ;
33
- o. push_str ( & format ! ( "{:width$} {}\n " , a. blue ( ) . bold( ) , b, width = left_pad) ) ;
34
+ o. push_str ( & format ! ( "{:width$} {}\n " , a. color ( color ) . bold( ) , b, width = left_pad) ) ;
34
35
}
35
36
36
37
write ! ( f, "{}" , o)
@@ -52,6 +53,24 @@ enum Language {
52
53
Ruby ,
53
54
}
54
55
56
+ fn get_color ( l : & Language ) -> & str {
57
+
58
+ match l {
59
+ Language :: Rust => "white" ,
60
+ Language :: Go => "blue" ,
61
+ Language :: Java => "green" ,
62
+ Language :: Cpp => "yellow" ,
63
+ Language :: C => "cyan" ,
64
+ Language :: Python => "magenta" ,
65
+ Language :: Csharp => "white" ,
66
+ Language :: Scala => "blue" ,
67
+ Language :: Shell => "green" ,
68
+ Language :: Lisp => "yellow" ,
69
+ Language :: Haskell => "cyan" ,
70
+ Language :: Ruby => "magenta" ,
71
+ }
72
+ }
73
+
55
74
impl fmt:: Display for Language {
56
75
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
57
76
match * self {
@@ -72,21 +91,17 @@ impl fmt::Display for Language {
72
91
}
73
92
74
93
fn main ( ) {
75
- let info = Info {
76
- project_name : String :: from ( "onefetch" ) ,
77
- language : Language :: Java ,
78
- author : String :: from ( "Ossama Hjaji" ) ,
79
- repo : String :: from ( "https://github.com/02sh/onefetch" ) ,
80
- number_of_lines : 15656 ,
81
- license : String :: from ( "MIT" ) ,
82
- } ;
94
+ let info = Info {
95
+ project_name : String :: from ( "onefetch" ) ,
96
+ language : Language :: Python ,
97
+ author : String :: from ( "Ossama Hjaji" ) ,
98
+ repo : String :: from ( "https://github.com/02sh/onefetch" ) ,
99
+ number_of_lines : 15656 ,
100
+ license : String :: from ( "MIT" ) ,
101
+ } ;
83
102
84
- println ! ( "{}" , info) ;
103
+ println ! ( "{}" , info) ;
85
104
86
- //let left_pad = ascii.lines().map(|l| l.len()).max().unwrap_or(0) + 5;
87
- //for (a,b) in ascii.lines().zip(info.lines()) {
88
- // println!("{:width$} {}", a, b, width = left_pad);
89
- //}
90
105
}
91
106
92
107
0 commit comments