internal: CheckRequestedWidth
Vladimir Bauer
5 years ago
| 113 | 113 |
}
|
| 114 | 114 |
|
| 115 | 115 |
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)
|
| 117 | 117 |
brackets := s.rwidth[rLeft] + s.rwidth[rRight]
|
| 118 | 118 |
if width < brackets {
|
| 119 | 119 |
return
|
| 42 | 42 |
}
|
| 43 | 43 |
|
| 44 | 44 |
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)
|
| 46 | 46 |
|
| 47 | 47 |
frame := s.frames[s.count%uint(len(s.frames))]
|
| 48 | 48 |
frameWidth := runewidth.StringWidth(frame)
|
| 0 | 0 |
package internal
|
| 1 | 1 |
|
| 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 {
|
| 4 | 6 |
return available
|
| 5 | 7 |
}
|
| 6 | |
return reqWidth
|
|
8 |
return requested
|
| 7 | 9 |
}
|