Skip to content

Commit

Permalink
Add a white space after prefix and before suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
jkawamoto committed Sep 24, 2021
1 parent 3058580 commit 4bd2f07
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions v3/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package pb
var (
// Full - preset with all default available elements
// Example: 'Prefix 20/100 [-->______] 20% 1 p/s ETA 1m Suffix'
Full ProgressBarTemplate = `{{string . "prefix"}}{{counters . }} {{bar . }} {{percent . }} {{speed . }} {{rtime . "ETA %s"}}{{string . "suffix"}}`
Full ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }} {{speed . }} {{rtime . "ETA %s"}}{{with string . "suffix"}} {{.}}{{end}}`

// Default - preset like Full but without elapsed time
// Example: 'Prefix 20/100 [-->______] 20% 1 p/s ETA 1m Suffix'
Default ProgressBarTemplate = `{{string . "prefix"}}{{counters . }} {{bar . }} {{percent . }} {{speed . }}{{string . "suffix"}}`
// Example: 'Prefix 20/100 [-->______] 20% 1 p/s Suffix'
Default ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }} {{speed . }}{{with string . "suffix"}} {{.}}{{end}}`

// Simple - preset without speed and any timers. Only counters, bar and percents
// Example: 'Prefix 20/100 [-->______] 20% Suffix'
Simple ProgressBarTemplate = `{{string . "prefix"}}{{counters . }} {{bar . }} {{percent . }}{{string . "suffix"}}`
Simple ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }}{{with string . "suffix"}} {{.}}{{end}}`
)
29 changes: 29 additions & 0 deletions v3/preset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pb

import (
"strings"
"testing"
)

func TestPreset(t *testing.T) {
prefix := "Prefix"
suffix := "Suffix"

for _, preset := range []ProgressBarTemplate{Full, Default, Simple} {
bar := preset.New(100).
SetCurrent(20).
Set("prefix", prefix).
Set("suffix", suffix).
SetWidth(50)

// initialize the internal state
_, _ = bar.render()
s := bar.String()
if !strings.HasPrefix(s, prefix+" ") {
t.Error("prefix not found:", s)
}
if !strings.HasSuffix(s, " "+suffix) {
t.Error("suffix not found:", s)
}
}
}

0 comments on commit 4bd2f07

Please sign in to comment.