@@ -12,6 +12,7 @@ use std::process::{Command, Stdio};
12
12
use std:: str:: FromStr ;
13
13
use license:: License ;
14
14
use std:: ffi:: OsStr ;
15
+ use std:: fmt:: Write ;
15
16
16
17
struct Info {
17
18
project_name : String ,
@@ -24,59 +25,77 @@ struct Info {
24
25
25
26
impl fmt:: Display for Info {
26
27
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
27
- let mut s = String :: from ( " \n " ) ;
28
+ let mut buffer = String :: new ( ) ;
28
29
let color = get_color ( & self . language ) ;
29
30
30
- s. push_str (
31
- & ( "Project: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . project_name) ) ,
32
- ) ;
33
-
34
- s. push_str (
35
- & ( "Language: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . language) ) ,
36
- ) ;
37
-
38
- if self . authors . len ( ) > 0 {
31
+ writeln ! (
32
+ buffer,
33
+ "{}{}" ,
34
+ "Project: " . color( color) . bold( ) ,
35
+ self . project_name
36
+ ) ?;
37
+ writeln ! (
38
+ buffer,
39
+ "{}{}" ,
40
+ "Language: " . color( color) . bold( ) ,
41
+ self . language
42
+ ) ?;
43
+
44
+ if !self . authors . is_empty ( ) {
39
45
let title = if self . authors . len ( ) > 1 {
40
46
"Authors: "
41
47
} else {
42
48
"Author: "
43
49
} ;
44
50
45
- let first = self . authors . first ( ) . unwrap ( ) ;
46
- s. push_str ( & ( title. color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , first) ) ) ;
51
+ writeln ! (
52
+ buffer,
53
+ "{}{}" ,
54
+ title. color( color) . bold( ) ,
55
+ self . authors. first( ) . unwrap( )
56
+ ) ?;
47
57
48
- let title = ( 0 .. title. len ( ) ) . map ( |_| " " ) . collect :: < String > ( ) ;
58
+ let title = " " . repeat ( title. len ( ) ) ;
49
59
50
60
for author in self . authors . iter ( ) . skip ( 1 ) {
51
- s . push_str ( & ( title. color ( color) . bold ( ) . to_string ( ) + & format ! ( "{} \n " , author) ) ) ;
61
+ writeln ! ( buffer , "{}{}" , title. color( color) . bold( ) , author) ? ;
52
62
}
53
63
}
54
64
55
- s. push_str ( & ( "Repo: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . repo) ) ) ;
56
- s. push_str (
57
- & ( "Number of lines: " . color ( color) . bold ( ) . to_string ( )
58
- + & format ! ( "{}\n " , self . number_of_lines) ) ,
59
- ) ;
60
- s. push_str ( & ( "License: " . color ( color) . bold ( ) . to_string ( ) + & format ! ( "{}\n " , self . license) ) ) ;
65
+ writeln ! ( buffer, "{}{}" , "Repo: " . color( color) . bold( ) , self . repo) ?;
66
+ writeln ! (
67
+ buffer,
68
+ "{}{}" ,
69
+ "Number of lines: " . color( color) . bold( ) ,
70
+ self . number_of_lines
71
+ ) ?;
72
+ writeln ! (
73
+ buffer,
74
+ "{}{}" ,
75
+ "License: " . color( color) . bold( ) ,
76
+ self . license
77
+ ) ?;
61
78
62
79
let logo = self . get_ascii ( ) ;
63
- let mut lines = s . lines ( ) ;
80
+ let mut lines = buffer . lines ( ) ;
64
81
let left_pad = logo. lines ( ) . map ( |l| l. len ( ) ) . max ( ) . unwrap_or ( 0 ) ;
65
- let mut o = String :: new ( ) ;
82
+
66
83
for a in logo. lines ( ) {
67
84
let b = match lines. next ( ) {
68
85
Some ( line) => line,
69
86
None => "" ,
70
87
} ;
71
- o. push_str ( & format ! (
72
- "{:width$} {}\n " ,
88
+
89
+ writeln ! (
90
+ f,
91
+ "{:width$} {}" ,
73
92
a. color( color) . bold( ) ,
74
93
b,
75
94
width = left_pad
76
- ) ) ;
95
+ ) ? ;
77
96
}
78
97
79
- write ! ( f , "{}" , o )
98
+ Ok ( ( ) )
80
99
}
81
100
}
82
101
@@ -168,8 +187,8 @@ fn main() {
168
187
169
188
let info = Info {
170
189
project_name : config. repository_name ,
171
- language : language ,
172
- authors : authors ,
190
+ language,
191
+ authors,
173
192
repo : config. repository_url ,
174
193
number_of_lines : get_total_loc ( & tokei_langs) ,
175
194
license : project_license ( ) ,
@@ -243,7 +262,7 @@ fn get_configuration() -> Result<Configuration, Error> {
243
262
} ;
244
263
245
264
let url = remote_url. clone ( ) ;
246
- let name_parts: Vec < & str > = url. split ( "/" ) . collect ( ) ;
265
+ let name_parts: Vec < & str > = url. split ( '/' ) . collect ( ) ;
247
266
248
267
if name_parts. len ( ) > 0 {
249
268
repository_name = name_parts[ name_parts. len ( ) - 1 ] . to_string ( ) ;
0 commit comments