Skip to content

Commit

Permalink
fix: use ANSI codes for colors instead to avoid bad flickering on est…
Browse files Browse the repository at this point in the history
…imated time display
  • Loading branch information
tphakala committed Dec 18, 2024
1 parent 595c67e commit 6db64eb
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions internal/analysis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"time"

"github.com/fatih/color"
"github.com/tphakala/birdnet-go/internal/birdnet"
"github.com/tphakala/birdnet-go/internal/conf"
"github.com/tphakala/birdnet-go/internal/datastore"
Expand Down Expand Up @@ -67,19 +66,15 @@ func FileAnalysis(settings *conf.Settings) error {
// Lets set predStart to 0 time
predStart := time.Time{}

// Add color functions
white := color.New(color.FgWhite)
yellow := color.New(color.FgYellow)
green := color.New(color.FgGreen)

// Process audio chunks as they're read
err = myaudio.ReadAudioFileBuffered(settings, func(chunk []float32) error {
chunkCount++
fmt.Printf("\r\033[K") // Clear line
white.Printf("📄 %s [%s]", filename, duration.Round(time.Second))
fmt.Print(" | ")
yellow.Printf("🔍 Analyzing chunk %d/%d ", chunkCount, totalChunks)
fmt.Print(birdnet.EstimateTimeRemaining(startTime, chunkCount, totalChunks))
fmt.Printf("\r\033[K\033[37m📄 %s [%s]\033[0m | \033[33m🔍 Analyzing chunk %d/%d\033[0m %s",
filename,
duration.Round(time.Second),
chunkCount,
totalChunks,
birdnet.EstimateTimeRemaining(startTime, chunkCount, totalChunks))

//notes, err := bn.ProcessChunk(chunk, float64(chunkCount-1)*(3-settings.BirdNET.Overlap))
notes, err := bn.ProcessChunk(chunk, predStart)
Expand All @@ -98,11 +93,11 @@ func FileAnalysis(settings *conf.Settings) error {
return fmt.Errorf("error processing audio: %w", err)
}

// Show total time taken for analysis
fmt.Printf("\r\033[K") // Clear line
white.Printf("📄 %s [%s]", filename, duration.Round(time.Second))
fmt.Print(" | ")
green.Printf("✅ Analysis completed in %s\n", birdnet.FormatDuration(time.Since(startTime)))
// Show total time taken for analysis, including audio length
fmt.Printf("\r\033[K\033[37m📄 %s [%s]\033[0m | \033[32m✅ Analysis completed in %s\033[0m\n",
filename,
duration.Round(time.Second),
birdnet.FormatDuration(time.Since(startTime)))

// Prepare the output file path if OutputDir is specified in the configuration.
var outputFile string
Expand Down

0 comments on commit 6db64eb

Please sign in to comment.