github.com/driusan/dgit@v0.0.0-20221118233547-f39f0c15edbb/git/progressf.go (about)

     1  //go:build !plan9
     2  // +build !plan9
     3  
     4  package git
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"time"
    10  )
    11  
    12  var lastProgress int64
    13  
    14  // Print progress information to stderr
    15  func progressF(fmtS string, done bool, args ...interface{}) {
    16  	if done {
    17  		fmt.Fprintf(os.Stderr, "\r"+fmtS+", done\n", args...)
    18  	}
    19  	now := time.Now().Unix()
    20  	if lastProgress > 0 && now-lastProgress < 3 {
    21  		return
    22  	}
    23  	fmt.Fprintf(os.Stderr, "\r"+fmtS, args...)
    24  	lastProgress = now
    25  }