Codebase list golang-github-vbauerster-mpb / 2dfd48b
internal: CheckRequestedWidth Vladimir Bauer 5 years ago
3 changed file(s) with 7 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
113113 }
114114
115115 func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
116 width := internal.WidthForBarFiller(reqWidth, stat.AvailableWidth)
116 width := internal.CheckRequestedWidth(reqWidth, stat.AvailableWidth)
117117 brackets := s.rwidth[rLeft] + s.rwidth[rRight]
118118 if width < brackets {
119119 return
4242 }
4343
4444 func (s *spinnerFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
45 width := internal.WidthForBarFiller(reqWidth, stat.AvailableWidth)
45 width := internal.CheckRequestedWidth(reqWidth, stat.AvailableWidth)
4646
4747 frame := s.frames[s.count%uint(len(s.frames))]
4848 frameWidth := runewidth.StringWidth(frame)
00 package internal
11
2 func WidthForBarFiller(reqWidth, available int) int {
3 if reqWidth <= 0 || reqWidth >= available {
2 // CheckRequestedWidth checks that requested width doesn't overflow
3 // available width
4 func CheckRequestedWidth(requested, available int) int {
5 if requested <= 0 || requested >= available {
46 return available
57 }
6 return reqWidth
8 return requested
79 }