From 28acea9d105cd816f83834b391411ee592163450 Mon Sep 17 00:00:00 2001 From: Daniel Milde Date: Sun, 11 Feb 2024 01:37:22 +0100 Subject: [PATCH] feat: correct message when calculating stats for non-interactive mode --- stdout/stdout.go | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/stdout/stdout.go b/stdout/stdout.go index 9697d0e75..5b1ecba84 100644 --- a/stdout/stdout.go +++ b/stdout/stdout.go @@ -134,15 +134,17 @@ func (ui *UI) ListDevices(getter device.DevicesInfoGetter) error { // AnalyzePath analyzes recursively disk usage in given path func (ui *UI) AnalyzePath(path string, _ fs.Item) error { var ( - dir fs.Item - wait sync.WaitGroup + dir fs.Item + wait sync.WaitGroup + updateStatsDone chan struct{} ) + updateStatsDone = make(chan struct{}, 1) if ui.ShowProgress { wait.Add(1) go func() { defer wait.Done() - ui.updateProgress() + ui.updateProgress(updateStatsDone) }() } @@ -151,6 +153,7 @@ func (ui *UI) AnalyzePath(path string, _ fs.Item) error { defer wait.Done() dir = ui.Analyzer.AnalyzeDir(path, ui.CreateIgnoreFunc(), ui.ConstGC) dir.UpdateStats(make(fs.HardLinkedItems, 10)) + updateStatsDone <- struct{}{} }() wait.Wait() @@ -322,14 +325,14 @@ func (ui *UI) showReadingProgress(doneChan chan struct{}) { } } -func (ui *UI) updateProgress() { +func (ui *UI) updateProgress(updateStatsDone <-chan struct{}) { emptyRow := "\r" for j := 0; j < 100; j++ { emptyRow += " " } progressChan := ui.Analyzer.GetProgressChan() - doneChan := ui.Analyzer.GetDone() + analysisDoneChan := ui.Analyzer.GetDone() var progress common.CurrentProgress @@ -339,9 +342,23 @@ func (ui *UI) updateProgress() { select { case progress = <-progressChan: - case <-doneChan: - fmt.Fprint(ui.output, "\r") - return + case <-analysisDoneChan: + for { + fmt.Fprint(ui.output, emptyRow) + fmt.Fprintf(ui.output, "\r %s ", string(progressRunes[i])) + fmt.Fprint(ui.output, "Calculating disk usage...") + time.Sleep(100 * time.Millisecond) + i++ + i %= 10 + + select { + case <-updateStatsDone: + fmt.Fprint(ui.output, emptyRow) + fmt.Fprint(ui.output, "\r") + return + default: + } + } } fmt.Fprintf(ui.output, "\r %s ", string(progressRunes[i]))