Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Jul 19, 2022
1 parent 578acb0 commit b6528f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ func main() {
"progress",
"p",
false,
"display progress of files",
"display progress of all files",
)
flags.BoolVar(
&processor.ProgressLarge,
"progress-large",
false,
"display progress of only large files",
)
flags.BoolVar(
&processor.Debug,
Expand Down
5 changes: 4 additions & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var Trace = false
// Progress uses ui bar to display the progress of files
var Progress = false

// ProgressLarge uses ui bar to display the progress of files
var ProgressLarge = false

// Recursive to walk directories
var Recursive = false

Expand Down Expand Up @@ -149,7 +152,7 @@ func Process() {
close(fileListQueue)
}()

if Progress {
if Progress || ProgressLarge {
uiprogress.Start() // start rendering of progress bars
}

Expand Down
14 changes: 12 additions & 2 deletions processor/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func fileProcessorWorker(input chan string, output chan Result) {
r, err = processReadFile(res, &content)
}

if Progress {
var bar *uiprogress.Bar
bar = uiprogress.AddBar(1) // Add a new bar
bar.AppendFunc(func(b *uiprogress.Bar) string {
split := strings.Split(file.Name(), "/")
return "file: " + split[len(split)-1]
})
bar.Set(1)
}

if Trace {
printTrace(fmt.Sprintf("nanoseconds processReadFileParallel: %s: %d", res, makeTimestampNano()-fileStartTime))
}
Expand Down Expand Up @@ -254,7 +264,7 @@ func processScanner(filename string, fsize int) (Result, error) {
}

var bar *uiprogress.Bar
if Progress {
if Progress || ProgressLarge {
bar = uiprogress.AddBar(fsize) // Add a new bar
bar.AppendFunc(func(b *uiprogress.Bar) string {
split := strings.Split(filename, "/")
Expand All @@ -271,7 +281,7 @@ func processScanner(filename string, fsize int) (Result, error) {
return Result{}, err
}

if Progress {
if Progress || ProgressLarge {
sum += n
_ = bar.Set(sum)
}
Expand Down

0 comments on commit b6528f3

Please sign in to comment.