mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-25 08:12:36 +02:00
move epubprogress
This commit is contained in:
parent
9601e0a9b4
commit
66b66a6b76
@ -4,6 +4,7 @@ create a progress bar with custom settings.
|
||||
package epubprogress
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
@ -20,18 +21,21 @@ type Options struct {
|
||||
TotalJob int
|
||||
}
|
||||
|
||||
type EpubProgress interface {
|
||||
type epubProgress interface {
|
||||
Add(num int) error
|
||||
Close() error
|
||||
}
|
||||
|
||||
func New(o Options) EpubProgress {
|
||||
func New(o Options) epubProgress {
|
||||
if o.Quiet {
|
||||
return progressbar.DefaultSilent(int64(o.Max))
|
||||
}
|
||||
|
||||
if o.Json {
|
||||
return newEpubProgressJson(o)
|
||||
return &epubProgressJson{
|
||||
o: o,
|
||||
e: json.NewEncoder(os.Stdout),
|
||||
}
|
||||
}
|
||||
|
||||
fmtJob := fmt.Sprintf("%%0%dd", len(fmt.Sprint(o.TotalJob)))
|
@ -2,23 +2,15 @@ package epubprogress
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
type EpubProgressJson struct {
|
||||
type epubProgressJson struct {
|
||||
o Options
|
||||
e *json.Encoder
|
||||
current int
|
||||
}
|
||||
|
||||
func newEpubProgressJson(o Options) EpubProgress {
|
||||
return &EpubProgressJson{
|
||||
o: o,
|
||||
e: json.NewEncoder(os.Stdout),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *EpubProgressJson) Add(num int) error {
|
||||
func (p *epubProgressJson) Add(num int) error {
|
||||
p.current += num
|
||||
p.e.Encode(map[string]any{
|
||||
"type": "progress",
|
||||
@ -37,6 +29,6 @@ func (p *EpubProgressJson) Add(num int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *EpubProgressJson) Close() error {
|
||||
func (p *epubProgressJson) Close() error {
|
||||
return nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user