func (cmd CmdCheck) newReadProgress(todo restic.Stat) *restic.Progress { if !cmd.global.ShowProgress() { return nil } readProgress := restic.NewProgress(time.Second) readProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) { status := fmt.Sprintf("[%s] %s %d / %d items", formatDuration(d), formatPercent(s.Blobs, todo.Blobs), s.Blobs, todo.Blobs) w, _, err := terminal.GetSize(int(os.Stdout.Fd())) if err == nil { if len(status) > w { max := w - len(status) - 4 status = status[:max] + "... " } } fmt.Printf("\x1b[2K%s\r", status) } readProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) { fmt.Printf("\nduration: %s\n", formatDuration(d)) } return readProgress }
func (cmd CmdBackup) newArchiveProgress(todo restic.Stat) *restic.Progress { if !cmd.global.ShowProgress() { return nil } archiveProgress := restic.NewProgress(time.Second) var bps, eta uint64 itemsTodo := todo.Files + todo.Dirs archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) { sec := uint64(d / time.Second) if todo.Bytes > 0 && sec > 0 && ticker { bps = s.Bytes / sec if s.Bytes >= todo.Bytes { eta = 0 } else if bps > 0 { eta = (todo.Bytes - s.Bytes) / bps } } itemsDone := s.Files + s.Dirs status1 := fmt.Sprintf("[%s] %s %s/s %s / %s %d / %d items %d errors ", formatDuration(d), formatPercent(s.Bytes, todo.Bytes), formatBytes(bps), formatBytes(s.Bytes), formatBytes(todo.Bytes), itemsDone, itemsTodo, s.Errors) status2 := fmt.Sprintf("ETA %s ", formatSeconds(eta)) w, _, err := terminal.GetSize(int(os.Stdout.Fd())) if err == nil { maxlen := w - len(status2) if maxlen < 4 { status1 = "" } else if len(status1) > maxlen { status1 = status1[:maxlen-4] status1 += "... " } } fmt.Printf("\x1b[2K%s%s\r", status1, status2) } archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) { fmt.Printf("\nduration: %s, %s\n", formatDuration(d), formatRate(todo.Bytes, d)) } return archiveProgress }
func (cmd CmdBackup) newScanProgress() *restic.Progress { if !cmd.global.ShowProgress() { return nil } p := restic.NewProgress(time.Second) p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) { fmt.Printf("\x1b[2K[%s] %d directories, %d files, %s\r", formatDuration(d), s.Dirs, s.Files, formatBytes(s.Bytes)) } p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) { fmt.Printf("\x1b[2Kscanned %d directories, %d files in %s\n", s.Dirs, s.Files, formatDuration(d)) } return p }