Closed zhijian-pro closed 1 year ago
@vbauerster what do you think?
只导出了 cwriter/writer_posix.go
下的 clearLines
方法,Windows 平台也需要导出吧
我把你的代码合并到我 fork 的仓库 https://github.com/wux1an/mpb 后,在 windows 和 linux 环境下都测试了。
linux 环境下正常,windows 环境下一定概率会把最后一行输出清除,导致少输出一行。
正常输出:
2022/04/10 10:24:12 0
2022/04/10 10:24:12 1
...
2022/04/10 10:24:13 28
2022/04/10 10:24:13 29
test 7s [==================>-------------------------------------------] 30 %
异常输出:
2022/04/10 10:24:12 0
2022/04/10 10:24:12 1
...
2022/04/10 10:24:13 28
package main
import (
"github.com/wux1an/mpb/v7"
"github.com/wux1an/mpb/v7/decor"
"log"
"time"
)
func main() {
var writer = mpb.New(mpb.WithWidth(64))
var bar = writer.New(
100,
mpb.BarStyle().Lbound("[").Filler("=").Tip(">").Padding("-").Rbound("]"),
mpb.PrependDecorators(
// display our name with one space on the right
decor.Name("test", decor.WC{W: len("test") + 1, C: decor.DidentRight}),
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
),
),
mpb.AppendDecorators(decor.Percentage()),
)
log.SetOutput(writer)
for i := 0; i < 30; i++ {
bar.Increment()
go func() {
log.Println(i)
}()
time.Sleep(100 * time.Millisecond)
}
}
@wux1an The bug has been fixed, and the log will not be lost now.
We can add a write interface for the use of external log modules to solve the problem of overlapping the log and the progress bar. The following is the usage