30 lines
624 B
Go
30 lines
624 B
Go
package spm
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
type Progress struct {
|
|
mu sync.Mutex
|
|
percentage int
|
|
task string
|
|
}
|
|
|
|
var progress = Progress{}
|
|
|
|
// UpdateProgress sets the current percentage and task.
|
|
func UpdateProgress(percentage int, task string) {
|
|
progress.mu.Lock()
|
|
defer progress.mu.Unlock()
|
|
progress.percentage = percentage
|
|
progress.task = task
|
|
fmt.Printf("\r[%3d%%] %s", percentage, task) // Print progress to the terminal
|
|
}
|
|
|
|
// GetProgress returns the current progress state.
|
|
func GetProgress() (int, string) {
|
|
progress.mu.Lock()
|
|
defer progress.mu.Unlock()
|
|
return progress.percentage, progress.task
|
|
}
|