这是indexloc提供的服务,不要输入任何密码
Skip to content

Need a way to wait progress bar output its final state #18

@cofyc

Description

@cofyc
package main

import (
    "time"

    "github.com/gosuri/uiprogress"
)

func main() {
    uiprogress.Start()            // start rendering
    bar := uiprogress.AddBar(100) // Add a new bar

    // optionally, append and prepend completion and elapsed time
    bar.AppendCompleted()
    bar.PrependElapsed()

    for bar.Incr() {
        time.Sleep(time.Millisecond * 1)
    }
}

If you reduce sleep time (less than uiprogress.RefreshInterval), the progress bar will not reach 100%, see:

$ go run example/simple/simple.go 
    0 [=================================================================>--]  97%

I think there should have a mechanism to make sure the outputs are consistent. A Flush() method?

For example:

for bar.Incr() {
    time.Sleep(time.Millisecond * 1)
}
uiprogress.Flush()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions