| 198 | } |
| 199 | |
| 200 | func (w *standardProgressWorker) run() { |
| 201 | hasBar := false |
| 202 | |
| 203 | for { |
| 204 | task := <-w.progress.queue |
| 205 | switch task.code { |
| 206 | case codeBarEnabled: |
| 207 | hasBar = true |
| 208 | case codeBarDisabled: |
| 209 | hasBar = false |
| 210 | case codePrint: |
| 211 | if w.progress.barShown { |
| 212 | fmt.Print("\r\033[2K") |
| 213 | w.progress.barShown = false |
| 214 | } |
| 215 | fmt.Print(task.message) |
| 216 | case codePrintStdErr: |
| 217 | if w.progress.barShown { |
| 218 | fmt.Print("\r\033[2K") |
| 219 | w.progress.barShown = false |
| 220 | } |
| 221 | fmt.Fprint(os.Stderr, task.message) |
| 222 | case codeProgress: |
| 223 | if hasBar { |
| 224 | fmt.Print("\r" + task.message) |
| 225 | w.progress.barShown = true |
| 226 | } |
| 227 | case codeHideProgress: |
| 228 | if w.progress.barShown { |
| 229 | fmt.Print("\r\033[2K") |
| 230 | w.progress.barShown = false |
| 231 | } |
| 232 | case codeFlush: |
| 233 | task.reply <- true |
| 234 | case codeStop: |
| 235 | w.progress.stopped <- true |
| 236 | return |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | type loggerProgressWorker struct { |
| 242 | progress *Progress |