diff --git a/pkg/builder/parser.go b/pkg/builder/parser.go index 82bc2c3..41a872a 100644 --- a/pkg/builder/parser.go +++ b/pkg/builder/parser.go @@ -71,6 +71,11 @@ func (p *Parser) processProgress(text string) bool { total int ) + // Don't show progress bars on small terminals. + if ui.ConsoleWidth() < 80 { + return false + } + sr := strings.NewReader(text) // Check if this is a progressbar-style output (e.g. "X out of Y"). if n, _ := fmt.Fscanf(sr, "(%d/%d) Wrote", &step, &total); n != 2 { @@ -89,7 +94,7 @@ func (p *Parser) processProgress(text string) bool { BarStart: "[", BarEnd: "]", }), - progressbar.OptionSetWidth(ui.ConsoleWidth()/2), + progressbar.OptionSetWidth(ui.ConsoleWidth()-20), ) } diff --git a/pkg/ui/ui.go b/pkg/ui/ui.go index a49d085..500fad0 100644 --- a/pkg/ui/ui.go +++ b/pkg/ui/ui.go @@ -6,6 +6,7 @@ import ( "os" "path" "strings" + "unicode/utf8" spin "github.com/tj/go-spin" "github.com/ttacon/chalk" @@ -17,6 +18,10 @@ var ( spinner = spin.New() ) +func init() { + spinner.Set(spin.Spin1) +} + func Info(msg string, args ...interface{}) { fmt.Printf("%s %s\n", chalk.Bold.TextStyle(chalk.Blue.Color("==>")), chalk.Bold.TextStyle(fmt.Sprintf(msg, args...))) } @@ -55,20 +60,24 @@ func ConsoleWidth() int { } func Live(msg string) { - lineLength := ConsoleWidth() - 5 - msg = strings.TrimSpace(msg) + // Format the message. + msg = fmt.Sprintf("%s %s", spinner.Next(), strings.TrimSpace(msg)) + + // Get the actual console width. + lineLength := ConsoleWidth() - // Truncate length - if len(msg) > lineLength { - msg = msg[0:lineLength-2] + "…" + // Shorten the message until it fits. + for utf8.RuneCountInString(msg) > lineLength { + msg = msg[0:len(msg)-4] + "…" } - // Pad with spaces to clear previous line. - for len(msg) < lineLength { - msg += " " + // Pad the message with spaces until it takes the entire line. + // This is in order to clear the previous line. + for utf8.RuneCountInString(msg) < lineLength { + msg = msg + " " } - fmt.Printf("%s %s\r", spinner.Next(), Small(msg)) + fmt.Printf("%s\r", Small(msg)) } func Tree(p string, ignore []string) error {