vbauerster / mpb

multi progress bar for Go cli applications
The Unlicense
2.29k stars 123 forks source link

Support for complex filler 'runes'? #86

Closed colecrouter closed 3 years ago

colecrouter commented 3 years ago

Suggestion: Allowing Fillers to have assignable strings instead of runes. This would allow users to insert colour codes, complex shapes, and more.

Instead of having:

mpb.NewBarFiller("[=> |"),

we could do something like this:

mpb.NewBarFiller("[", "=", ">", "|"),
vbauerster commented 3 years ago

Well "complex runes" are supported, for example it's ok to pass string with emoji if that makes sense. Color codes can be added by means of decorators. I don't plan to change default bar filler, but don't mind having an alternative implementation.

PR is welcome!

colecrouter commented 3 years ago

I'm not sure I understand, could you give an example? I'd be more than happy to fork (as soon as I get a spare minute hahaha).

vbauerster commented 3 years ago

Following patch will make bar red.

diff --git a/_examples/singleBar/main.go b/_examples/singleBar/main.go
index f0ba8ea..20c8675 100644
--- a/_examples/singleBar/main.go
+++ b/_examples/singleBar/main.go
@@ -25,8 +25,12 @@ func main() {
            decor.OnComplete(
                decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
            ),
+           decor.Name("\x1b[31m"),
+       ),
+       mpb.AppendDecorators(
+           decor.Name("\x1b[0m"),
+           decor.Percentage(),
        ),
-       mpb.AppendDecorators(decor.Percentage()),
    )
    // simulating some work
    max := 100 * time.Millisecond
colecrouter commented 3 years ago

Ah thank you, I see what you mean. I'll see what I can do.

colecrouter commented 3 years ago

Check out #88 :P

vbauerster commented 3 years ago

@Mexican-Man Thanks for your contribution and idea.

I've implemented this feature in v7, see related example.