mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
add throttling and interface
This commit is contained in:
parent
77d6600a36
commit
4a3fc60732
@ -6,6 +6,7 @@ package epubprogress
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
)
|
)
|
||||||
@ -18,7 +19,12 @@ type Options struct {
|
|||||||
TotalJob int
|
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 {
|
if o.Quiet {
|
||||||
return progressbar.DefaultSilent(int64(o.Max))
|
return progressbar.DefaultSilent(int64(o.Max))
|
||||||
}
|
}
|
||||||
@ -26,6 +32,7 @@ func New(o Options) *progressbar.ProgressBar {
|
|||||||
fmtDesc := fmt.Sprintf("[%s/%s] %%-15s", fmtJob, fmtJob)
|
fmtDesc := fmt.Sprintf("[%s/%s] %%-15s", fmtJob, fmtJob)
|
||||||
return progressbar.NewOptions(o.Max,
|
return progressbar.NewOptions(o.Max,
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
|
progressbar.OptionThrottle(65*time.Millisecond),
|
||||||
progressbar.OptionOnCompletion(func() {
|
progressbar.OptionOnCompletion(func() {
|
||||||
fmt.Fprint(os.Stderr, "\n")
|
fmt.Fprint(os.Stderr, "\n")
|
||||||
}),
|
}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user