added SPM
All checks were successful
/ test-on-windows (push) Successful in 9s
/ test-on-alpine (push) Successful in 4s

This commit is contained in:
partisan 2024-12-25 10:58:31 +01:00
parent 17bb547c74
commit 9e5457c2ec
8 changed files with 779 additions and 18 deletions

30
spm/progress.go Normal file
View file

@ -0,0 +1,30 @@
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
}