Pad bar name with spaces (approx. size due to escape codes)

dev
Manuel Bua 2020-07-25 21:03:18 +02:00
parent bb24061628
commit d8e69cacf2
1 changed files with 11 additions and 11 deletions

View File

@ -52,8 +52,8 @@ func (p *Progress) SetupTemplateProgressbar(templateId string, requestCount int6
uiBarName = uiBarName[:MaxLen] + ".." uiBarName = uiBarName[:MaxLen] + ".."
} }
barName := color.BrightYellow(uiBarName).String() uiBarName = fmt.Sprintf(fmt.Sprintf("%%-%ds", MaxLen), "[" + color.BrightYellow(uiBarName).String() + "]")
bar := p.setupProgressbar(barName, requestCount, priority) bar := p.setupProgressbar(uiBarName, requestCount, priority)
p.bars[templateId] = &Bar{ p.bars[templateId] = &Bar{
bar: bar, bar: bar,
@ -62,13 +62,6 @@ func (p *Progress) SetupTemplateProgressbar(templateId string, requestCount int6
} }
} }
func pluralize(count int64, singular, plural string) string {
if count > 1 {
return plural
}
return singular
}
// Creates and returns a progress bar that tracks all the requests progress. // Creates and returns a progress bar that tracks all the requests progress.
// This is only useful when multiple templates are processed within the same run. // This is only useful when multiple templates are processed within the same run.
func (p *Progress) SetupGlobalProgressbar(hostCount int64, templateCount int, requestCount int64) { func (p *Progress) SetupGlobalProgressbar(hostCount int64, templateCount int, requestCount int64) {
@ -85,7 +78,7 @@ func (p *Progress) SetupGlobalProgressbar(hostCount int64, templateCount int, re
color.Bold(color.Cyan(hostCount)), color.Bold(color.Cyan(hostCount)),
pluralize(hostCount, "host", "hosts")) pluralize(hostCount, "host", "hosts"))
bar := p.setupProgressbar(barName, requestCount, 0) bar := p.setupProgressbar("[" + barName + "]", requestCount, 0)
p.gbar = &Bar{ p.gbar = &Bar{
bar: bar, bar: bar,
@ -94,6 +87,13 @@ func (p *Progress) SetupGlobalProgressbar(hostCount int64, templateCount int, re
} }
} }
func pluralize(count int64, singular, plural string) string {
if count > 1 {
return plural
}
return singular
}
// Update progress tracking information and increments the request counter by one unit. // Update progress tracking information and increments the request counter by one unit.
// If a global progress bar is present it will be updated as well. // If a global progress bar is present it will be updated as well.
func (p *Progress) Update(templateId string) { func (p *Progress) Update(templateId string) {
@ -130,7 +130,7 @@ func (p *Progress) setupProgressbar(name string, total int64, priority int) *mpb
mpb.BarNoPop(), mpb.BarNoPop(),
mpb.BarRemoveOnComplete(), mpb.BarRemoveOnComplete(),
mpb.PrependDecorators( mpb.PrependDecorators(
decor.Name(fmt.Sprintf("[%s]", name), decor.WCSyncSpaceR), decor.Name(name, decor.WCSyncSpaceR),
decor.CountersNoUnit(color.BrightBlue(" %d/%d").String(), decor.WCSyncSpace), decor.CountersNoUnit(color.BrightBlue(" %d/%d").String(), decor.WCSyncSpace),
decor.NewPercentage(color.Bold("%d").String(), decor.WCSyncSpace), decor.NewPercentage(color.Bold("%d").String(), decor.WCSyncSpace),
), ),