argo-cd

Форк
0
/
progress_bar.go 
47 строк · 984.0 Байт
1
package util
2

3
import (
4
	"fmt"
5
)
6

7
// Bar ...
8
type Bar struct {
9
	percent int64  // progress percentage
10
	cur     int64  // current progress
11
	total   int64  // total value for progress
12
	rate    string // the actual progress bar to be printed
13
	graph   string // the fill value for progress bar
14
}
15

16
func (bar *Bar) NewOption(start, total int64) {
17
	bar.cur = start
18
	bar.total = total
19
	if bar.graph == "" {
20
		bar.graph = "█"
21
	}
22
	bar.percent = bar.getPercent()
23
	for i := 0; i < int(bar.percent); i += 2 {
24
		bar.rate += bar.graph // initial progress position
25
	}
26
}
27

28
func (bar *Bar) getPercent() int64 {
29
	return int64((float32(bar.cur) / float32(bar.total)) * 100)
30
}
31

32
func (bar *Bar) Increment() {
33
	bar.cur += 1
34
}
35

36
func (bar *Bar) Play() {
37
	last := bar.percent
38
	bar.percent = bar.getPercent()
39
	if bar.percent != last && bar.percent%2 == 0 {
40
		bar.rate += bar.graph
41
	}
42
	fmt.Printf("\r[%-50s]%3d%% %8d/%d", bar.rate, bar.percent, bar.cur, bar.total)
43
}
44

45
func (bar *Bar) Finish() {
46
	fmt.Println()
47
}
48

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.