You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/filex/progressscanner.go

33 lines
634 B
Go

4 years ago
package filex
import "gopkg.in/cheggaaa/pb.v1"
type (
// A Scanner is used to read lines.
4 years ago
Scanner interface {
// Scan checks if it has remaining to read.
4 years ago
Scan() bool
// Text returns next line.
4 years ago
Text() string
}
progressScanner struct {
Scanner
bar *pb.ProgressBar
}
)
// NewProgressScanner returns a Scanner with progress indicator.
4 years ago
func NewProgressScanner(scanner Scanner, bar *pb.ProgressBar) Scanner {
return &progressScanner{
Scanner: scanner,
bar: bar,
}
}
func (ps *progressScanner) Text() string {
s := ps.Scanner.Text()
ps.bar.Add64(int64(len(s)) + 1) // take newlines into account
return s
}