Bar*_*ort 5

我正在寻求实现类似的功能并遇到了这个问题。不确定您是否仍在寻找解决方案,但我找到了一个:)

uiliveNewline()*uilive.Writer
writer := uilive.New()       // writer for the first line
writer2 := writer.Newline()  // writer for the second line
// start listening for updates and render
writer.Start()

for i := 0; i <= 100; i++ {
    fmt.Fprintf(writer, "Downloading File 1.. %d %%\n", i)
    fmt.Fprintf(writer2, "Downloading File 2.. %d %%\n", i)
    time.Sleep(time.Millisecond * 5)
}

fmt.Fprintln(writer, "Finished downloading both files :)")
writer.Stop() // flush and stop rendering

为了实现一些东西来跟踪多个同时运行的任务的进度,正如@blami 的回答还指出的那样,一个好的方法是有一个单独的 goroutine 来处理所有终端输出。

mllintprintTasks
RefreshDurationtime.HourFlush()printTasks