13
13
term_size,
14
14
} ;
15
15
16
+ const MAX_TERM_WIDTH : usize = 95 ;
17
+
16
18
pub struct Cli {
17
19
pub repo_path : String ,
18
20
pub ascii_input : Option < String > ,
@@ -95,7 +97,7 @@ impl Cli {
95
97
. help ( "Takes a non-empty STRING as input to replace the ASCII logo." )
96
98
. long_help (
97
99
"Takes a non-empty STRING as input to replace the ASCII logo. \
98
- It is possible to pass a generated STRING by command substitution. \
100
+ It is possible to pass a generated STRING by command substitution. \n \
99
101
For example:\n \
100
102
'--ascii-input \" $(fortune | cowsay -W 25)\" '"
101
103
)
@@ -130,7 +132,7 @@ impl Cli {
130
132
. help ( "Changes the text colors (X X X...)." )
131
133
. long_help (
132
134
"Changes the text colors (X X X...). \
133
- Goes in order of title, ~, underline, subtitle, colon, and info. \
135
+ Goes in order of title, ~, underline, subtitle, colon, and info. \n \
134
136
For example:\n \
135
137
'--text-colors 9 10 11 12 13 14'"
136
138
)
@@ -218,49 +220,27 @@ impl Cli {
218
220
. takes_value ( true )
219
221
. help ( "Ignore all files & directories matching EXCLUDE." ) ,
220
222
)
221
- . arg (
222
- Arg :: with_name ( "show-logo" )
223
- . short ( "S" )
224
- . long ( "show-logo" )
225
- . takes_value ( false )
226
- . help ( "If ASCII logo should be shown in all circumstances." )
227
- . conflicts_with ( "hide-logo" )
228
- )
229
223
. arg (
230
224
Arg :: with_name ( "hide-logo" )
231
- . short ( "H" )
232
225
. long ( "hide-logo" )
233
- . takes_value ( false )
234
- . help ( "If ASCII logo should be hidden in all circumstances." )
235
- . conflicts_with ( "show-logo" )
236
- )
237
- . arg (
238
- Arg :: with_name ( "max-width" )
239
- . short ( "w" )
240
- . long ( "max-width" )
241
- . value_name ( "AMOUNT" )
226
+ . value_name ( "WHEN" )
242
227
. takes_value ( true )
243
- . max_values ( 1 )
244
- . default_value ( "95" )
245
- . help ( "If ASCII logo should be hidden when terminal width is below AMOUNT." )
246
- . validator (
247
- |t| {
248
- t. parse :: < u32 > ( )
249
- . map_err ( |_t| "must be a number" )
250
- . map ( |_t|( ) )
251
- . map_err ( |e| e. to_string ( ) )
252
- } ,
228
+ . possible_values ( & [ "auto" , "never" , "always" ] )
229
+ . default_value ( "always" )
230
+ . hide_default_value ( true )
231
+ . help ( "Specify when to hide the logo (auto, never, *always*)." )
232
+ . long_help (
233
+ "Specify when to hide the logo (auto, never, *always*). \n \
234
+ If set to auto, the logo will be hidden if the terminal's width < 95."
253
235
)
254
236
) . get_matches ( ) ;
255
237
238
+ let true_color = cli_utils:: is_truecolor_terminal ( ) ;
256
239
let no_bold = matches. is_present ( "no-bold" ) ;
257
240
let no_merges = matches. is_present ( "no-merge-commits" ) ;
258
241
let no_color_palette = matches. is_present ( "no-color-palette" ) ;
259
242
let print_languages = matches. is_present ( "languages" ) ;
260
243
let print_package_managers = matches. is_present ( "package-managers" ) ;
261
- let mut art_off = matches. is_present ( "hide-logo" ) || !matches. is_present ( "show-logo" ) ;
262
- let true_color = cli_utils:: is_truecolor_terminal ( ) ;
263
- let max_term_size: usize = matches. value_of ( "max-width" ) . unwrap ( ) . parse ( ) . unwrap ( ) ;
264
244
265
245
let fields_to_hide: Vec < String > = if let Some ( values) = matches. values_of ( "disable-fields" )
266
246
{
@@ -269,6 +249,19 @@ impl Cli {
269
249
Vec :: new ( )
270
250
} ;
271
251
252
+ let art_off = match matches. value_of ( "hide-logo" ) {
253
+ Some ( "always" ) => true ,
254
+ Some ( "never" ) => false ,
255
+ Some ( "auto" ) => {
256
+ if let Some ( ( width, _) ) = term_size:: dimensions_stdout ( ) {
257
+ width < MAX_TERM_WIDTH
258
+ } else {
259
+ false
260
+ }
261
+ }
262
+ _ => unreachable ! ( "other values for --hide-logo are not allowed" ) ,
263
+ } ;
264
+
272
265
let image = if let Some ( image_path) = matches. value_of ( "image" ) {
273
266
Some ( image:: open ( image_path) . chain_err ( || "Could not load the specified image" ) ?)
274
267
} else {
@@ -285,17 +278,6 @@ impl Cli {
285
278
None
286
279
} ;
287
280
288
- if !matches. is_present ( "hide-logo" ) && !matches. is_present ( "show-logo" ) {
289
- if let Some ( ( width, _) ) = term_size:: dimensions_stdout ( ) {
290
- art_off = width <= max_term_size;
291
- } else {
292
- std:: eprintln!(
293
- "{}" ,
294
- ( "Could not get terminal width. ASCII art will be displayed." )
295
- ) ;
296
- }
297
- }
298
-
299
281
if image. is_some ( ) && image_backend. is_none ( ) {
300
282
return Err ( "Could not detect a supported image backend" . into ( ) ) ;
301
283
}
0 commit comments