vbauerster / mpb

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

Allow multi-rune strings as BarFiller. #88

Closed colecrouter closed 3 years ago

colecrouter commented 3 years ago

Before:

mpb.NewBarFiller("╢▌▌░╟")
// or
NewBarFillerPick("", true) // Empty returns default bar filler

After:

mpb.NewBarFiller("╢","▌","▌","░","╟")
// or
NewBarFillerPick(true) // Spread operator after, ie "(true, "[", "=", etc..)"

Keeps all previous mechanics in place, such as uniseg.NewGraphemes(), and utf8.ValidString(). Added edge case for Bash colour codes to fix the width. Tested with all examples, works fine. Testing with my own custom filler (with colours), works fine:

mpb.NewBarFiller("\u001b[36;1m", "_", "\u001b[30;1m|\\\u001b[36;1m", "_", "\u001b[0m") // Shark :P

Note: when using Bash colour codes, there seems to be a reflow on the first frame (while width is calculated). I don't think this really matters, as it also takes a frame to calculate the width on normal bars.

Updated docs and examples as best as I can see, everything compiles and runs no problem. Please let me know if I overlooked something.

vbauerster commented 3 years ago

I don't plan to change default bar filler, but don't mind having an alternative implementation.

You have altered default bar filler implementation. I don't want to make breaking changes. Please do your implementation in subpackage, so it will coexists with default one.

What I'm expecting to see at the end:

import (
    "github.com/vbauerster/mpb/v6"
        cbf "github.com/vbauerster/mpb/v6/your-cool-barfiller"
    "github.com/vbauerster/mpb/v6/decor"
)

func main() {
    p := mpb.New()

    bar := p.Add(100,
        cbf.NewBarFiller("╢","▌","▌","░","╟"),
                ...
       )
}
colecrouter commented 3 years ago

I misunderstood what you said earlier about implementation; my bad.

I've gone ahead and added a BarComplexFiller type (same way as SpinnerFiller, along with it's own functions, as an extended implementation of BarFiller. I also added an example in _examples/.

This shouldn't change/break the current implemented methods. Let me know if this works. Thanks.

vbauerster commented 3 years ago

NewBarComplexFillerRev didn't work for me and I still want it to be in subpackage.

colecrouter commented 3 years ago

I think I've got this nested package set up like you describe. I also fixed the issue with Rev. I had trouble testing it with the nested package, but I think I have it figured out; if you pull the fork, then uncomment line 7 in the go.mod for _examples/fillerComplex/, it should run.

vbauerster commented 3 years ago

I've implemented this feature in v7.