MCPcopy
hub / github.com/containerd/containerd / Format

Method Format

pkg/progress/bar.go:36–82  ·  view source on GitHub ↗

Format the progress bar as output

(state fmt.State, r rune)

Source from the content-addressed store, hash-verified

34
35// Format the progress bar as output
36func (h Bar) Format(state fmt.State, r rune) {
37 switch r {
38 case 'r':
39 default:
40 panic(fmt.Sprintf("%v: unexpected format character", float64(h)))
41 }
42
43 if h > 1.0 {
44 h = 1.0
45 }
46
47 if h < 0.0 {
48 h = 0.0
49 }
50
51 if state.Flag('-') {
52 h = 1.0 - h
53 }
54
55 width, ok := state.Width()
56 if !ok {
57 // default width of 40
58 width = 40
59 }
60
61 var pad int
62
63 extra := len([]byte(green)) + len([]byte(reset))
64
65 p := make([]byte, width+extra)
66 p[0], p[len(p)-1] = '|', '|'
67 pad += 2
68
69 positive := int(Bar(width-pad) * h)
70 negative := width - pad - positive
71
72 n := 1
73 n += copy(p[n:], green)
74 n += copy(p[n:], bytes.Repeat([]byte("+"), positive))
75 n += copy(p[n:], reset)
76
77 if negative > 0 {
78 copy(p[n:len(p)-1], bytes.Repeat([]byte("-"), negative))
79 }
80
81 state.Write(p)
82}

Callers 15

DeleteMethod · 0.80
CheckpointMethod · 0.80
LoadContainerMethod · 0.80
unpackMethod · 0.80
testsuite.goFile · 0.80
checkUpdateFunction · 0.80
WithExpirationFunction · 0.80
TestGCRootsFunction · 0.80
TestGCRemoveFunction · 0.80
TestGCRefsFunction · 0.80
TestCollectibleResourcesFunction · 0.80
CreateMethod · 0.80

Calls 2

BarTypeAlias · 0.85
WriteMethod · 0.65

Tested by 5

TestGCRootsFunction · 0.64
TestGCRemoveFunction · 0.64
TestGCRefsFunction · 0.64
TestCollectibleResourcesFunction · 0.64