Exemple #1
0
func (p *ProgressMeter) update() {
	if p.dryRun || p.estimatedFiles == 0 {
		return
	}

	width := 80 // default to 80 chars wide if ts.GetSize() fails
	size, err := ts.GetSize()
	if err == nil {
		width = size.Col()
	}

	// (%d of %d files, %d skipped) %f B / %f B, %f B skipped
	// skipped counts only show when > 0

	out := fmt.Sprintf("\r(%d of %d files", p.finishedFiles, p.estimatedFiles)
	if p.skippedFiles > 0 {
		out += fmt.Sprintf(", %d skipped", p.skippedFiles)
	}
	out += fmt.Sprintf(") %s / %s", formatBytes(p.currentBytes), formatBytes(p.estimatedBytes))
	if p.skippedBytes > 0 {
		out += fmt.Sprintf(", %s skipped", formatBytes(p.skippedBytes))
	}

	padding := strings.Repeat(" ", width-len(out))
	fmt.Fprintf(os.Stdout, out+padding)
}
Exemple #2
0
func (s *Spinner) update(out io.Writer, prefix, msg string) {

	str := fmt.Sprintf("%v %v", prefix, msg)

	width := 80 // default to 80 chars wide if ts.GetSize() fails
	size, err := ts.GetSize()
	if err == nil {
		width = size.Col()
	}
	padding := strings.Repeat(" ", width-len(str))

	fmt.Fprintf(out, "\r%v%v", str, padding)

}
Exemple #3
0
func terminalWidth() (int, error) {
	size, err := ts.GetSize()
	return size.Col(), err
}