[golang]golang如何覆蓋輸出console,實現進度條
package main import( "fmt" "os" "time" ) func main(){ for i :=0;i!=10;i=i+1{ fmt.Fprintf(os.Stdout,"result is %d\r",i) time.Sleep(time.Second*1) } fmt.Println("Over") }
golang一個騷氣的進度提示庫
spinner is a simple package to add a spinner / progress indicator to any terminal application. Examples can be found below as well as full examples in the examples directory.
For more detail about the library and its features, reference your local godoc once installed.
Contributions welcome!
安裝
go get -u -v github.com/briandowns/spinner
下面是效果圖
(Numbered by their slice index)
示例
package main import ( "github.com/briandowns/spinner" "time" ) func main() { s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner s.Start() // Start the spinner time.Sleep(4 * time.Second) // Run for some time to simulate work s.Stop() }
更多內容請看github
https://github.com/briandowns/spinner