mirror of
https://github.com/NohamR/papeer.git
synced 2026-05-25 12:27:20 +00:00
test tomobi, update progress style
This commit is contained in:
@@ -2,6 +2,7 @@ package book
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/gosuri/uiprogress"
|
||||
)
|
||||
@@ -11,20 +12,22 @@ type progress struct {
|
||||
individuals []*uiprogress.Bar
|
||||
}
|
||||
|
||||
func NewProgress(links []link) progress {
|
||||
func NewProgress(links []link, parent string, depth int) progress {
|
||||
uiprogress.Start()
|
||||
|
||||
global := uiprogress.AddBar(len(links))
|
||||
indentGlobal := strings.Repeat("> ", depth)
|
||||
global.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
return fmt.Sprintf("Chapters %d / %d", b.Current(), len(links))
|
||||
return fmt.Sprintf("%v%v (%v / %v)", indentGlobal, parent, b.Current(), len(links))
|
||||
})
|
||||
|
||||
// hide individual bars if more than 50 chapters
|
||||
individuals := []*uiprogress.Bar{}
|
||||
indent := strings.Repeat("- ", depth)
|
||||
if len(links) <= 50 {
|
||||
for index, link := range links {
|
||||
bar := uiprogress.AddBar(1)
|
||||
barText := fmt.Sprintf("%d. %s", index+1, link.text)
|
||||
barText := fmt.Sprintf("%v#%v %v", indent, index+1, link.Text())
|
||||
bar.AppendFunc(func(b *uiprogress.Bar) string {
|
||||
return barText
|
||||
})
|
||||
@@ -35,13 +38,22 @@ func NewProgress(links []link) progress {
|
||||
return progress{global, individuals}
|
||||
}
|
||||
|
||||
func (p *progress) IncrGlobal() {
|
||||
func (p *progress) IncrementGlobal() {
|
||||
p.global.Incr()
|
||||
}
|
||||
|
||||
func (p *progress) Incr(index int) {
|
||||
p.global.Incr()
|
||||
func (p *progress) Increment(index int) {
|
||||
p.IncrementGlobal()
|
||||
if len(p.individuals) > index {
|
||||
p.individuals[index].Incr()
|
||||
}
|
||||
}
|
||||
|
||||
func (p *progress) UpdateName(index int, name string) {
|
||||
if len(p.individuals) > index {
|
||||
barText := fmt.Sprintf("%s", name)
|
||||
p.individuals[index].AppendFunc(func(b *uiprogress.Bar) string {
|
||||
return barText
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user