11use std:: fs;
22use std:: io:: Read ;
33
4+ extern crate ansi_term;
45extern crate clap;
56
7+ use ansi_term:: Colour :: { Blue , Green } ;
68use clap:: { Arg , App } ;
79
810// FileStats holds information about an individual file
@@ -74,71 +76,71 @@ impl WcStats {
7476
7577 fn print_all ( self ) {
7678 for stat in self . stats {
77- println ! ( "{}\t {}\t {}\t {}" , stat. lines, stat. words, stat. characters, stat. name) ;
79+ println ! ( "{}\t {}\t {}\t {}" , stat. lines, stat. words, stat. characters, Green . dimmed ( ) . paint ( stat. name) ) ;
7880 }
7981
8082 if self . number_of_files > 1 {
81- println ! ( "{}\t {}\t {}\t total " , self . total. lines, self . total. words, self . total. characters) ;
83+ println ! ( "{}\t {}\t {}\t {} " , self . total. lines, self . total. words, self . total. characters, Blue . bold ( ) . paint ( "total" ) ) ;
8284 }
8385 }
8486
8587 fn print_lines_and_words ( self ) {
8688 for stat in self . stats {
87- println ! ( "{}\t {}\t {}" , stat. lines, stat. words, stat. name) ;
89+ println ! ( "{}\t {}\t {}" , stat. lines, stat. words, Green . dimmed ( ) . paint ( stat. name) ) ;
8890 }
8991
9092 if self . number_of_files > 1 {
91- println ! ( "{}\t {}\t total " , self . total. lines, self . total. words) ;
93+ println ! ( "{}\t {}\t {} " , self . total. lines, self . total. words, Blue . bold ( ) . paint ( "total" ) ) ;
9294 }
9395 }
9496
9597 fn print_lines_and_chars ( self ) {
9698 for stat in self . stats {
97- println ! ( "{}\t {}\t {}" , stat. lines, stat. characters, stat. name) ;
99+ println ! ( "{}\t {}\t {}" , stat. lines, stat. characters, Green . dimmed ( ) . paint ( stat. name) ) ;
98100 }
99101
100102 if self . number_of_files > 1 {
101- println ! ( "{}\t {}\t total " , self . total. lines, self . total. characters) ;
103+ println ! ( "{}\t {}\t {} " , self . total. lines, self . total. characters, Blue . bold ( ) . paint ( "total" ) ) ;
102104 }
103105 }
104106
105107 fn print_words_and_chars ( self ) {
106108 for stat in self . stats {
107- println ! ( "{}\t {}\t {}" , stat. words, stat. characters, stat. name) ;
109+ println ! ( "{}\t {}\t {}" , stat. words, stat. characters, Green . dimmed ( ) . paint ( stat. name) ) ;
108110 }
109111
110112 if self . number_of_files > 1 {
111- println ! ( "{}\t {}\t total " , self . total. words, self . total. characters) ;
113+ println ! ( "{}\t {}\t {} " , self . total. words, self . total. characters, Blue . bold ( ) . paint ( "total" ) ) ;
112114 }
113115 }
114116
115117 fn print_lines ( self ) {
116118 for stat in self . stats {
117- println ! ( "{}\t {}" , stat. lines, stat. name) ;
119+ println ! ( "{}\t {}" , stat. lines, Green . dimmed ( ) . paint ( stat. name) ) ;
118120 }
119121
120122 if self . number_of_files > 1 {
121- println ! ( "{}\t total " , self . total. lines) ;
123+ println ! ( "{}\t {} " , self . total. lines, Blue . bold ( ) . paint ( "total" ) ) ;
122124 }
123125 }
124126
125127 fn print_words ( self ) {
126128 for stat in self . stats {
127- println ! ( "{}\t {}" , stat. words, stat. name) ;
129+ println ! ( "{}\t {}" , stat. words, Green . dimmed ( ) . paint ( stat. name) ) ;
128130 }
129131
130132 if self . number_of_files > 1 {
131- println ! ( "{}\t total " , self . total. words) ;
133+ println ! ( "{}\t {} " , self . total. words, Blue . bold ( ) . paint ( "total" ) ) ;
132134 }
133135 }
134136
135137 fn print_chars ( self ) {
136138 for stat in self . stats {
137- println ! ( "{}\t {}" , stat. characters, stat. name) ;
139+ println ! ( "{}\t {}" , stat. characters, Green . dimmed ( ) . paint ( stat. name) ) ;
138140 }
139141
140142 if self . number_of_files > 1 {
141- println ! ( "{}\t total " , self . total. characters) ;
143+ println ! ( "{}\t {} " , self . total. characters, Blue . bold ( ) . paint ( "total" ) ) ;
142144 }
143145 }
144146}
@@ -151,9 +153,9 @@ TODOs:
151153- docs/comments
152154- add line lenght flag L
153155- add bytes flag c
156+ - error propogation
154157
155158Ehancements:
156- - Add color to the output, themes maybe?
157159- Add a recursive call to process files under directories
158160*/
159161fn main ( ) {
0 commit comments