diff options
Diffstat (limited to 'lex-fetch/progress')
-rw-r--r-- | lex-fetch/progress/progress.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lex-fetch/progress/progress.go b/lex-fetch/progress/progress.go new file mode 100644 index 0000000..430d36e --- /dev/null +++ b/lex-fetch/progress/progress.go @@ -0,0 +1,27 @@ +package progress + +import ( + "fmt" + "io" + "sync" +) + +type Reporter struct { + Total int + cur int + mu sync.Mutex + writer io.Writer +} + +func NewReporter(writer io.Writer) Reporter { + return Reporter{writer: writer} +} + +func (r *Reporter) ReportProgress(num int) { + r.mu.Lock() + if num > r.cur { + fmt.Fprintf(r.writer, "%d/%d\n", num, r.Total) + r.cur = num + } + r.mu.Unlock() +} |