progressscanner.go 457 B

12345678910111213141516171819202122232425262728
  1. package filex
  2. import "gopkg.in/cheggaaa/pb.v1"
  3. type (
  4. Scanner interface {
  5. Scan() bool
  6. Text() string
  7. }
  8. progressScanner struct {
  9. Scanner
  10. bar *pb.ProgressBar
  11. }
  12. )
  13. func NewProgressScanner(scanner Scanner, bar *pb.ProgressBar) Scanner {
  14. return &progressScanner{
  15. Scanner: scanner,
  16. bar: bar,
  17. }
  18. }
  19. func (ps *progressScanner) Text() string {
  20. s := ps.Scanner.Text()
  21. ps.bar.Add64(int64(len(s)) + 1) // take newlines into account
  22. return s
  23. }