MCPcopy Index your code
hub / github.com/aylei/kubectl-debug / String

Method String

pkg/util/jsonstream.go:46–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func (p *JSONProgress) String() string {
47 var (
48 width = 200
49 pbBox string
50 numbersBox string
51 timeLeftBox string
52 )
53
54 ws, err := term.GetWinsize(p.terminalFd)
55 if err == nil {
56 width = int(ws.Width)
57 }
58
59 if p.Current <= 0 && p.Total <= 0 {
60 return ""
61 }
62 if p.Total <= 0 {
63 switch p.Units {
64 case "":
65 current := units.HumanSize(float64(p.Current))
66 return fmt.Sprintf("%8v", current)
67 default:
68 return fmt.Sprintf("%d %s", p.Current, p.Units)
69 }
70 }
71
72 percentage := int(float64(p.Current)/float64(p.Total)*100) / 2
73 if percentage > 50 {
74 percentage = 50
75 }
76 if width > 110 {
77 // this number can't be negative gh#7136
78 numSpaces := 0
79 if 50-percentage > 0 {
80 numSpaces = 50 - percentage
81 }
82 pbBox = fmt.Sprintf("[%s>%s] ", strings.Repeat("=", percentage), strings.Repeat(" ", numSpaces))
83 }
84
85 switch {
86 case p.HideCounts:
87 case p.Units == "": // no units, use bytes
88 current := units.HumanSize(float64(p.Current))
89 total := units.HumanSize(float64(p.Total))
90
91 numbersBox = fmt.Sprintf("%8v/%v", current, total)
92
93 if p.Current > p.Total {
94 // remove total display if the reported current is wonky.
95 numbersBox = fmt.Sprintf("%8v", current)
96 }
97 default:
98 numbersBox = fmt.Sprintf("%d/%d %s", p.Current, p.Total, p.Units)
99
100 if p.Current > p.Total {
101 // remove total display if the reported current is wonky.
102 numbersBox = fmt.Sprintf("%d %s", p.Current, p.Units)
103 }

Callers 2

RunMethod · 0.80
DisplayMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected