@@ -3,7 +3,7 @@ use crate::utils::pretty_print;
33use crate :: utils:: progress;
44use crate :: utils:: remote:: Fetcher ;
55
6- use super :: { GITHUB_RAW_BASE , ensure_gitignore_cache, find_template_in_cache} ;
6+ use super :: { ensure_gitignore_cache, find_template_in_cache, GITHUB_RAW_BASE } ;
77
88#[ derive( clap:: Args , Debug , Clone ) ]
99pub struct PreviewArgs {
@@ -14,6 +14,10 @@ pub struct PreviewArgs {
1414 /// Update the gitignore cache
1515 #[ arg( long = "update-cache" ) ]
1616 pub update_cache : bool ,
17+
18+ /// Disable colored output
19+ #[ arg( long = "no-color" ) ]
20+ pub no_color : bool ,
1721}
1822
1923impl super :: Runnable for PreviewArgs {
@@ -28,17 +32,21 @@ impl super::Runnable for PreviewArgs {
2832 let cache = ensure_gitignore_cache ( & mut cache_manager, self . update_cache ) ?;
2933
3034 for template_name in & self . args {
31- preview_single_template ( template_name, & cache) ?;
35+ preview_single_template ( template_name, & cache, self . no_color ) ?;
3236 }
3337
3438 Ok ( ( ) )
3539 }
3640}
3741
38- fn preview_single_template ( template : & str , cache : & super :: Cache < String > ) -> anyhow:: Result < ( ) > {
42+ fn preview_single_template (
43+ template : & str ,
44+ cache : & super :: Cache < String > ,
45+ no_color : bool ,
46+ ) -> anyhow:: Result < ( ) > {
3947 // normalize template if it has the .gitignore ext
4048 let template = template. strip_suffix ( ".gitignore" ) . unwrap_or ( template) ;
41-
49+
4250 // Find the template path in cache
4351 let template_path = find_template_in_cache ( template, cache) ?;
4452
@@ -51,7 +59,10 @@ fn preview_single_template(template: &str, cache: &super::Cache<String>) -> anyh
5159 pb. set_message ( msg) ;
5260 pb. finish_and_clear ( ) ;
5361
54- println ! ( "\n === Preview: {} === \n " , template) ;
55- pretty_print:: print_highlighted ( "gitignore" , & content) ;
62+ if no_color {
63+ println ! ( "{}" , content) ;
64+ } else {
65+ pretty_print:: print_highlighted ( "gitignore" , & content) ;
66+ }
5667 Ok ( ( ) )
5768}
0 commit comments