1010 clippy:: style,
1111 clippy:: suspicious
1212) ]
13- #![ allow(
14- clippy:: cast_possible_truncation,
15- clippy:: cast_precision_loss,
16- clippy:: cast_sign_loss,
17- clippy:: let_underscore_untyped,
18- clippy:: struct_excessive_bools,
19- clippy:: too_many_arguments
20- ) ]
13+ #![ allow( clippy:: cast_precision_loss, clippy:: struct_excessive_bools) ]
2114
2215use clap:: CommandFactory ;
2316use context:: { layout, Context } ;
24- use progress:: Message ;
17+ use progress:: { Indicator , IndicatorHandle , Message } ;
2518use render:: { Engine , Flat , FlatInverted , Inverted , Regular } ;
26- use std:: { error:: Error , io:: stdout, process:: ExitCode , sync :: Arc } ;
19+ use std:: { error:: Error , io:: stdout, process:: ExitCode } ;
2720use tree:: Tree ;
2821
2922/// Operations to wrangle ANSI escaped strings.
@@ -44,10 +37,7 @@ mod icons;
4437/// Concerned with displaying a progress indicator when stdout is a tty.
4538mod progress;
4639
47- /// Concerned with taking an initialized [`Tree`] and its [`Node`]s and rendering the output.
48- ///
49- /// [`Tree`]: tree::Tree
50- /// [`Node`]: tree::node::Node
40+ /// Concerned with taking an initialized [`tree::Tree`] and its [`tree::node::Node`]s and rendering the output.
5141mod render;
5242
5343/// Global used throughout the program to paint the output.
@@ -80,29 +70,18 @@ fn run() -> Result<(), Box<dyn Error>> {
8070 return Ok ( ( ) ) ;
8171 }
8272
83- context:: color:: no_color_env ( ) ;
84-
8573 styles:: init ( ctx. no_color ( ) ) ;
8674
87- let indicator = ( ctx. stdout_is_tty && !ctx. no_progress )
88- . then ( progress:: Indicator :: measure)
89- . map ( Arc :: new) ;
75+ let indicator = Indicator :: maybe_init ( & ctx) ;
9076
91- if indicator. is_some ( ) {
92- let indicator = indicator. clone ( ) ;
93-
94- ctrlc:: set_handler ( move || {
95- let _ = progress:: IndicatorHandle :: terminate ( indicator. clone ( ) ) ;
96- tty:: restore_tty ( ) ;
97- } ) ?;
98- }
99-
100- let ( tree, ctx) = match Tree :: try_init ( ctx, indicator. clone ( ) ) {
101- Ok ( res) => res,
102- Err ( err) => {
103- let _ = progress:: IndicatorHandle :: terminate ( indicator) ;
104- return Err ( Box :: new ( err) ) ;
105- } ,
77+ let ( tree, ctx) = {
78+ match Tree :: try_init ( ctx, indicator. as_ref ( ) ) {
79+ Ok ( res) => res,
80+ Err ( err) => {
81+ IndicatorHandle :: terminate ( indicator) ;
82+ return Err ( Box :: new ( err) ) ;
83+ } ,
84+ }
10685 } ;
10786
10887 macro_rules! compute_output {
@@ -122,12 +101,11 @@ fn run() -> Result<(), Box<dyn Error>> {
122101 if let Some ( mut progress) = indicator {
123102 progress. mailbox ( ) . send ( Message :: RenderReady ) ?;
124103
125- if let Some ( hand) = Arc :: get_mut ( & mut progress) {
126- hand. join_handle
127- . take ( )
128- . map ( |h| h. join ( ) . unwrap ( ) )
129- . transpose ( ) ?;
130- }
104+ progress
105+ . join_handle
106+ . take ( )
107+ . map ( |h| h. join ( ) . unwrap ( ) )
108+ . transpose ( ) ?;
131109 }
132110
133111 #[ cfg( debug_assertions) ]
0 commit comments