前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[golang]golang如何覆盖输出console,实现进度条;golang一个骚气的进度提示库

[golang]golang如何覆盖输出console,实现进度条;golang一个骚气的进度提示库

作者头像
landv
修改2019-09-19 14:12:31
1.3K0
修改2019-09-19 14:12:31
举报
文章被收录于专栏:landvlandv

https://cloud.tencent.com/developer/article/1509173

golanggolang如何覆盖输出console,实现进度条

代码语言:javascript
复制
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!

安装

代码语言:javascript
复制
go get -u -v github.com/briandowns/spinner

下面是效果图

(Numbered by their slice index)

index

character set

sample gif

0

←↖↑↗→↘↓↙

1

▁▃▄▅▆▇█▇▆▅▄▃▁

2

▖▘▝▗

3

┤┘┴└├┌┬┐

4

◢◣◤◥

5

◰◳◲◱

6

◴◷◶◵

7

◐◓◑◒

8

.oO@*

9

| /-

10

◡◡⊙⊙◠◠

11

⣾⣽⣻⢿⡿⣟⣯⣷

12

))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<

13

⠁⠂⠄⡀⢀⠠⠐⠈

14

⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏

15

abcdefghijklmnopqrstuvwxyz

16

▉▊▋▌▍▎▏▎▍▌▋▊▉

17

■□▪▫

18

←↑→↓

19

╫╪

20

⇐⇖⇑⇗⇒⇘⇓⇙

21

⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈

22

⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈

23

⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁

24

⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋

25

ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン

26

. .. ...

27

▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁

28

.oO°Oo.

29

+x

30

v<^>

31

---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<

32

代码语言:| ​ |
复制

33

== ==== ====== ======== ==========

34

(*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)

35

█▒▒▒▒▒▒▒▒▒ ███▒▒▒▒▒▒▒ █████▒▒▒▒▒ ███████▒▒▒ ██████████

36

===> ======> ==========> ==============> ==================>

37

? ? ? ? ? ? ? ? ? ? ? ?

38

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

39

? ? ?

40

◜ ◝ ◞ ◟

41

⬒ ⬔ ⬓ ⬕

42

⬖ ⬘ ⬗ ⬙

43

>>> >>>>> >>>> >>>> >>>> >>>>

示例

代码语言:javascript
复制
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

代码语言:javascript
复制
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  •  golang一个骚气的进度提示库
    • 安装
      • 下面是效果图
        • 示例
          • 更多内容请看github
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档