[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
本文介绍在Golang中如何使用os.Stdout实现控制台输出的覆盖,以创建进度条效果,并展示了briandowns/spinner库的使用,该库提供多种字符集样式,用于在终端应用程序中添加旋转指示器或进度提示。










































890

被折叠的 条评论
为什么被折叠?



