From 4a3fc60732915bb9e3c31851fbaf978dd1c8d1d9 Mon Sep 17 00:00:00 2001 From: celogeek <65178+celogeek@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:10:46 +0200 Subject: [PATCH] add throttling and interface --- internal/epub/progress/epub_progress.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/epub/progress/epub_progress.go b/internal/epub/progress/epub_progress.go index 21dd011..8066718 100644 --- a/internal/epub/progress/epub_progress.go +++ b/internal/epub/progress/epub_progress.go @@ -6,6 +6,7 @@ package epubprogress import ( "fmt" "os" + "time" "github.com/schollz/progressbar/v3" ) @@ -18,7 +19,12 @@ type Options struct { TotalJob int } -func New(o Options) *progressbar.ProgressBar { +type EpubProgress interface { + Add(num int) error + Close() (err error) +} + +func New(o Options) EpubProgress { if o.Quiet { return progressbar.DefaultSilent(int64(o.Max)) } @@ -26,6 +32,7 @@ func New(o Options) *progressbar.ProgressBar { fmtDesc := fmt.Sprintf("[%s/%s] %%-15s", fmtJob, fmtJob) return progressbar.NewOptions(o.Max, progressbar.OptionSetWriter(os.Stderr), + progressbar.OptionThrottle(65*time.Millisecond), progressbar.OptionOnCompletion(func() { fmt.Fprint(os.Stderr, "\n") }),