From 467b0a10046337570b9a7d21f6e4609c79ecf809 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 20 Jun 2023 11:16:27 -0500 Subject: [PATCH] chore: restyle provisioner job output format (#8106) Reduce colors and formatting to reduce bugs and increase UNIX-feel. --- cli/cliui/provisionerjob.go | 25 ++++++++++--------------- cmd/cliui/main.go | 2 +- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cli/cliui/provisionerjob.go b/cli/cliui/provisionerjob.go index f8282465a3..28a12cdfe5 100644 --- a/cli/cliui/provisionerjob.go +++ b/cli/cliui/provisionerjob.go @@ -63,7 +63,6 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp var ( currentStage = "Queued" currentStageStartedAt = time.Now().UTC() - didLogBetweenStage = false errChan = make(chan error, 1) job codersdk.ProvisionerJob @@ -71,27 +70,26 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp ) printStage := func() { - _, _ = fmt.Fprintf(writer, DefaultStyles.Prompt.Render("⧗")+"%s\n", DefaultStyles.Field.Render(currentStage)) + _, _ = fmt.Fprintf(writer, "==> ⧗ %s\n", currentStage) } updateStage := func(stage string, startedAt time.Time) { if currentStage != "" { - prefix := "" - if !didLogBetweenStage { - prefix = "\033[1A\r" - } - mark := DefaultStyles.Checkmark + mark := "✔" if job.CompletedAt != nil && job.Status != codersdk.ProvisionerJobSucceeded { - mark = DefaultStyles.Crossmark + mark = "✘" } - _, _ = fmt.Fprintf(writer, prefix+mark.String()+DefaultStyles.Placeholder.Render(" %s [%dms]")+"\n", currentStage, startedAt.Sub(currentStageStartedAt).Milliseconds()) + dur := startedAt.Sub(currentStageStartedAt).Milliseconds() + if dur < 0 { + dur = 0 + } + _, _ = fmt.Fprintf(writer, "=== %s %s [%dms]\n", mark, currentStage, dur) } if stage == "" { return } currentStage = stage currentStageStartedAt = startedAt - didLogBetweenStage = false printStage() } @@ -129,7 +127,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp return } } - _, _ = fmt.Fprintf(writer, "\033[2K\r\n"+DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n") + _, _ = fmt.Fprintf(writer, DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n") err := opts.Cancel() if err != nil { errChan <- xerrors.Errorf("cancel: %w", err) @@ -222,10 +220,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp jobMutex.Unlock() continue } - _, _ = fmt.Fprintf(logOutput, "%s %s\n", DefaultStyles.Placeholder.Render(" "), output) - if !opts.Silent { - didLogBetweenStage = true - } + _, _ = fmt.Fprintf(logOutput, "%s\n", output) jobMutex.Unlock() } } diff --git a/cmd/cliui/main.go b/cmd/cliui/main.go index ccbff650d2..b75727dbb7 100644 --- a/cmd/cliui/main.go +++ b/cmd/cliui/main.go @@ -272,7 +272,7 @@ func main() { }, }) - err := root.Invoke(os.Args[1:]...).Run() + err := root.Invoke(os.Args[1:]...).WithOS().Run() if err != nil { _, _ = fmt.Println(err.Error()) os.Exit(1)