| 100 | 100 |
|
| 101 | 101 |
// SetWidth overrides width of individual bar
|
| 102 | 102 |
func (b *Bar) SetWidth(n int) *Bar {
|
| 103 | |
if n < 2 || IsClosed(b.done) {
|
|
103 |
if n < 2 || isClosed(b.done) {
|
| 104 | 104 |
return b
|
| 105 | 105 |
}
|
| 106 | 106 |
b.widthCh <- n
|
|
| 109 | 109 |
|
| 110 | 110 |
// TrimLeftSpace removes space befor LeftEnd charater
|
| 111 | 111 |
func (b *Bar) TrimLeftSpace() *Bar {
|
| 112 | |
if IsClosed(b.done) {
|
|
112 |
if isClosed(b.done) {
|
| 113 | 113 |
return b
|
| 114 | 114 |
}
|
| 115 | 115 |
b.trimLeftCh <- true
|
|
| 118 | 118 |
|
| 119 | 119 |
// TrimRightSpace removes space after RightEnd charater
|
| 120 | 120 |
func (b *Bar) TrimRightSpace() *Bar {
|
| 121 | |
if IsClosed(b.done) {
|
|
121 |
if isClosed(b.done) {
|
| 122 | 122 |
return b
|
| 123 | 123 |
}
|
| 124 | 124 |
b.trimRightCh <- true
|
|
| 127 | 127 |
|
| 128 | 128 |
// Format overrides format of individual bar
|
| 129 | 129 |
func (b *Bar) Format(format string) *Bar {
|
| 130 | |
if utf8.RuneCountInString(format) != numFmtRunes || IsClosed(b.done) {
|
|
130 |
if utf8.RuneCountInString(format) != numFmtRunes || isClosed(b.done) {
|
| 131 | 131 |
return b
|
| 132 | 132 |
}
|
| 133 | 133 |
b.formatCh <- format
|
|
| 138 | 138 |
// Defaults to 0.25
|
| 139 | 139 |
// Normally you shouldn't touch this
|
| 140 | 140 |
func (b *Bar) SetEtaAlpha(a float64) *Bar {
|
| 141 | |
if IsClosed(b.done) {
|
|
141 |
if isClosed(b.done) {
|
| 142 | 142 |
return b
|
| 143 | 143 |
}
|
| 144 | 144 |
b.etaAlphaCh <- a
|
|
| 152 | 152 |
|
| 153 | 153 |
// Incr increments progress bar
|
| 154 | 154 |
func (b *Bar) Incr(n int) {
|
| 155 | |
if n < 1 || IsClosed(b.done) {
|
|
155 |
if n < 1 || isClosed(b.done) {
|
| 156 | 156 |
return
|
| 157 | 157 |
}
|
| 158 | 158 |
b.incrCh <- int64(n)
|
|
| 160 | 160 |
|
| 161 | 161 |
// IncrWithReFill increments pb with different fill character
|
| 162 | 162 |
func (b *Bar) IncrWithReFill(n int, r rune) {
|
| 163 | |
if IsClosed(b.done) {
|
|
163 |
if isClosed(b.done) {
|
| 164 | 164 |
return
|
| 165 | 165 |
}
|
| 166 | 166 |
b.Incr(n)
|
|
| 195 | 195 |
// InProgress returns true, while progress is running
|
| 196 | 196 |
// Can be used as condition in for loop
|
| 197 | 197 |
func (b *Bar) InProgress() bool {
|
| 198 | |
return !IsClosed(b.done)
|
|
198 |
return !isClosed(b.done)
|
| 199 | 199 |
}
|
| 200 | 200 |
|
| 201 | 201 |
// PrependFunc prepends DecoratorFunc
|
| 202 | 202 |
func (b *Bar) PrependFunc(f DecoratorFunc) *Bar {
|
| 203 | |
if IsClosed(b.done) {
|
|
203 |
if isClosed(b.done) {
|
| 204 | 204 |
return b
|
| 205 | 205 |
}
|
| 206 | 206 |
b.decoratorCh <- &decorator{decPrepend, f}
|
|
| 209 | 209 |
|
| 210 | 210 |
// RemoveAllPrependers removes all prepend functions
|
| 211 | 211 |
func (b *Bar) RemoveAllPrependers() {
|
| 212 | |
if IsClosed(b.done) {
|
|
212 |
if isClosed(b.done) {
|
| 213 | 213 |
return
|
| 214 | 214 |
}
|
| 215 | 215 |
b.decoratorCh <- &decorator{decPrependZero, nil}
|
|
| 217 | 217 |
|
| 218 | 218 |
// AppendFunc appends DecoratorFunc
|
| 219 | 219 |
func (b *Bar) AppendFunc(f DecoratorFunc) *Bar {
|
| 220 | |
if IsClosed(b.done) {
|
|
220 |
if isClosed(b.done) {
|
| 221 | 221 |
return b
|
| 222 | 222 |
}
|
| 223 | 223 |
b.decoratorCh <- &decorator{decAppend, f}
|
|
| 226 | 226 |
|
| 227 | 227 |
// RemoveAllAppenders removes all append functions
|
| 228 | 228 |
func (b *Bar) RemoveAllAppenders() {
|
| 229 | |
if IsClosed(b.done) {
|
|
229 |
if isClosed(b.done) {
|
| 230 | 230 |
return
|
| 231 | 231 |
}
|
| 232 | 232 |
b.decoratorCh <- &decorator{decAppendZero, nil}
|
|
| 236 | 236 |
// You should call this method when total is unknown and you've reached the point
|
| 237 | 237 |
// of process completion.
|
| 238 | 238 |
func (b *Bar) Completed() {
|
| 239 | |
if IsClosed(b.done) {
|
|
239 |
if isClosed(b.done) {
|
| 240 | 240 |
return
|
| 241 | 241 |
}
|
| 242 | 242 |
b.completeReqCh <- struct{}{}
|
| 243 | 243 |
}
|
| 244 | 244 |
|
| 245 | 245 |
func (b *Bar) getState() state {
|
| 246 | |
if IsClosed(b.done) {
|
|
246 |
if isClosed(b.done) {
|
| 247 | 247 |
return b.state
|
| 248 | 248 |
}
|
| 249 | 249 |
ch := make(chan state, 1)
|
|
| 333 | 333 |
}
|
| 334 | 334 |
|
| 335 | 335 |
func (b *Bar) flushed() {
|
| 336 | |
if IsClosed(b.done) {
|
|
336 |
if isClosed(b.done) {
|
| 337 | 337 |
return
|
| 338 | 338 |
}
|
| 339 | 339 |
b.flushedCh <- struct{}{}
|
| 340 | 340 |
}
|
| 341 | 341 |
|
| 342 | 342 |
func (b *Bar) remove() {
|
| 343 | |
if IsClosed(b.done) {
|
|
343 |
if isClosed(b.done) {
|
| 344 | 344 |
return
|
| 345 | 345 |
}
|
| 346 | 346 |
b.removeReqCh <- struct{}{}
|