(write func(line string, args ...any))
| 391 | } |
| 392 | |
| 393 | func ProgressWriter(write func(line string, args ...any)) io.WriteCloser { |
| 394 | reader, writer := io.Pipe() |
| 395 | done := make(chan struct{}) |
| 396 | go func() { |
| 397 | defer close(done) |
| 398 | data := make([]byte, 4096) |
| 399 | for { |
| 400 | read, err := reader.Read(data) |
| 401 | if err != nil { |
| 402 | return |
| 403 | } |
| 404 | content := data[:read] |
| 405 | for _, line := range strings.Split(string(content), "\r") { |
| 406 | if line == "" { |
| 407 | continue |
| 408 | } |
| 409 | // Escape % signs so that they don't get interpreted as format specifiers |
| 410 | line = strings.Replace(line, "%", "%%", -1) |
| 411 | write(strings.TrimSpace(line)) |
| 412 | } |
| 413 | } |
| 414 | }() |
| 415 | |
| 416 | return &progressWriter{ |
| 417 | WriteCloser: writer, |
| 418 | r: reader, |
| 419 | done: done, |
| 420 | } |
| 421 | } |
no outgoing calls
no test coverage detected