@@ -34,7 +34,7 @@ type actionLogger struct {
3434	highlight  func (a  ... interface {}) string 
3535
3636	progress  * progress 
37- 	out       io.Writer 
37+ 	out       io.WriteCloser 
3838
3939	mu          sync.Mutex 
4040	logFiles    map [string ]* os.File 
@@ -82,6 +82,7 @@ func (a *actionLogger) ActionFailed(err error, patches []PatchInput) {
8282	if  ! a .verbose  {
8383		return 
8484	}
85+ 	a .out .Close ()
8586	fmt .Fprintln (os .Stderr )
8687	if  perr , ok  :=  err .(parallel.Errors ); ok  {
8788		if  len (patches ) >  0  {
@@ -108,6 +109,7 @@ func (a *actionLogger) ActionSuccess(patches []PatchInput, newLines bool) {
108109	if  ! a .verbose  {
109110		return 
110111	}
112+ 	a .out .Close ()
111113	fmt .Fprintln (os .Stderr )
112114	format  :=  "✔  Action produced %d patches." 
113115	if  newLines  {
@@ -306,18 +308,17 @@ type progressWriter struct {
306308	w                  io.Writer 
307309	shouldClear        bool 
308310	progressLogLength  int 
311+ 	closed             bool 
309312}
310313
311314func  (w  * progressWriter ) Write (data  []byte ) (int , error ) {
312315	w .mu .Lock ()
313316	defer  w .mu .Unlock ()
314317
315- 	if  w .shouldClear  {
316- 		// Clear current progress 
317- 		fmt .Fprintf (w .w , "\r " )
318- 		fmt .Fprintf (w .w , strings .Repeat (" " , w .progressLogLength ))
319- 		fmt .Fprintf (w .w , "\r " )
318+ 	if  w .closed  {
319+ 		return  0 , fmt .Errorf ("writer closed" )
320320	}
321+ 	w .clear ()
321322
322323	if  w .p .TotalSteps () ==  0  {
323324		// Don't display bar until we know number of steps 
@@ -353,3 +354,22 @@ func (w *progressWriter) Write(data []byte) (int, error) {
353354	w .progressLogLength  =  len (progessText )
354355	return  n , err 
355356}
357+ 
358+ // Close clears the progress bar and disallows further writing 
359+ func  (w  * progressWriter ) Close () error  {
360+ 	w .mu .Lock ()
361+ 	defer  w .mu .Unlock ()
362+ 
363+ 	w .clear ()
364+ 	w .closed  =  true 
365+ 	return  nil 
366+ }
367+ 
368+ func  (w  * progressWriter ) clear () {
369+ 	if  ! w .shouldClear  {
370+ 		return 
371+ 	}
372+ 	fmt .Fprintf (w .w , "\r " )
373+ 	fmt .Fprintf (w .w , strings .Repeat (" " , w .progressLogLength ))
374+ 	fmt .Fprintf (w .w , "\r " )
375+ }
0 commit comments