mexican bar example: style with Meta
Vladimir Bauer
2 years ago
| 0 | 0 | package main |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | "fmt" | |
| 3 | 4 | "math/rand" |
| 4 | 5 | "time" |
| 5 | 6 | |
| 14 | 15 | total := 100 |
| 15 | 16 | name := "Complex Filler:" |
| 16 | 17 | bs := mpb.BarStyle() |
| 17 | bs.Lbound("[\u001b[36;1m") | |
| 18 | bs.Filler("_") | |
| 19 | bs.Tip("\u001b[0m⛵\u001b[36;1m") | |
| 20 | bs.Padding("_") | |
| 21 | bs.Rbound("\u001b[0m]") | |
| 18 | bs.LboundMeta(func(s string) string { | |
| 19 | return fmt.Sprint("\033[34m", s, "\033[0m") // blue | |
| 20 | }) | |
| 21 | bs.Filler("_").FillerMeta(func(s string) string { | |
| 22 | return fmt.Sprint("\033[36m", s, "\033[0m") // cyan | |
| 23 | }) | |
| 24 | bs.Tip("⛵").TipMeta(func(s string) string { | |
| 25 | return fmt.Sprint("\033[31m", s, "\033[0m") // red | |
| 26 | }) | |
| 27 | bs.TipOnComplete() // leave tip on complete | |
| 28 | bs.Padding("_").PaddingMeta(func(s string) string { | |
| 29 | return fmt.Sprint("\033[36m", s, "\033[0m") // cyan | |
| 30 | }) | |
| 31 | bs.RboundMeta(func(s string) string { | |
| 32 | return fmt.Sprint("\033[34m", s, "\033[0m") // blue | |
| 33 | }) | |
| 22 | 34 | bar := p.New(int64(total), bs, |
| 23 | 35 | mpb.PrependDecorators(decor.Name(name)), |
| 24 | 36 | mpb.AppendDecorators(decor.Percentage()), |