mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 00:02:37 +02:00
In order to let third parties use the package of this library, we moved the pkg folder out of the locked internal folder
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
// Package epubprogress create a progress bar with custom settings.
|
|
package epubprogress
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/schollz/progressbar/v3"
|
|
|
|
"github.com/celogeek/go-comic-converter/v2/pkg/utils"
|
|
)
|
|
|
|
type Options struct {
|
|
Quiet bool
|
|
Json bool
|
|
Max int
|
|
Description string
|
|
CurrentJob int
|
|
TotalJob int
|
|
}
|
|
|
|
type EPUBProgress interface {
|
|
Add(num int) error
|
|
Close() error
|
|
}
|
|
|
|
func New(o Options) EPUBProgress {
|
|
if o.Quiet {
|
|
return progressbar.DefaultSilent(int64(o.Max))
|
|
}
|
|
|
|
if o.Json {
|
|
return &jsonprogress{
|
|
o: o,
|
|
e: json.NewEncoder(os.Stdout),
|
|
}
|
|
}
|
|
|
|
fmtJob := utils.FormatNumberOfDigits(o.TotalJob)
|
|
return progressbar.NewOptions(o.Max,
|
|
progressbar.OptionSetWriter(os.Stderr),
|
|
progressbar.OptionThrottle(65*time.Millisecond),
|
|
progressbar.OptionOnCompletion(func() {
|
|
utils.Println()
|
|
}),
|
|
progressbar.OptionSetDescription(fmt.Sprintf(
|
|
"["+fmtJob+"/"+fmtJob+"] %-15s",
|
|
o.CurrentJob,
|
|
o.TotalJob,
|
|
o.Description,
|
|
)),
|
|
progressbar.OptionSetWidth(60),
|
|
progressbar.OptionShowCount(),
|
|
progressbar.OptionSetRenderBlankState(true),
|
|
progressbar.OptionEnableColorCodes(true),
|
|
progressbar.OptionSetTheme(progressbar.Theme{
|
|
Saucer: "[green]=[reset]",
|
|
SaucerHead: "[green]>[reset]",
|
|
SaucerPadding: " ",
|
|
BarStart: "[",
|
|
BarEnd: "]",
|
|
}),
|
|
)
|
|
}
|