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
|
package epubprogress
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -20,18 +21,21 @@ type Options struct {
|
|||||||
TotalJob int
|
TotalJob int
|
||||||
}
|
}
|
||||||
|
|
||||||
type EpubProgress interface {
|
type epubProgress interface {
|
||||||
Add(num int) error
|
Add(num int) error
|
||||||
Close() error
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(o Options) EpubProgress {
|
func New(o Options) epubProgress {
|
||||||
if o.Quiet {
|
if o.Quiet {
|
||||||
return progressbar.DefaultSilent(int64(o.Max))
|
return progressbar.DefaultSilent(int64(o.Max))
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.Json {
|
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)))
|
fmtJob := fmt.Sprintf("%%0%dd", len(fmt.Sprint(o.TotalJob)))
|
@ -2,23 +2,15 @@ package epubprogress
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type EpubProgressJson struct {
|
type epubProgressJson struct {
|
||||||
o Options
|
o Options
|
||||||
e *json.Encoder
|
e *json.Encoder
|
||||||
current int
|
current int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEpubProgressJson(o Options) EpubProgress {
|
func (p *epubProgressJson) Add(num int) error {
|
||||||
return &EpubProgressJson{
|
|
||||||
o: o,
|
|
||||||
e: json.NewEncoder(os.Stdout),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *EpubProgressJson) Add(num int) error {
|
|
||||||
p.current += num
|
p.current += num
|
||||||
p.e.Encode(map[string]any{
|
p.e.Encode(map[string]any{
|
||||||
"type": "progress",
|
"type": "progress",
|
||||||
@ -37,6 +29,6 @@ func (p *EpubProgressJson) Add(num int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EpubProgressJson) Close() error {
|
func (p *epubProgressJson) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user