From a57de37ce03d3b780d88b8d30bce816948c222ac Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 20 Jun 2023 15:29:24 +0000 Subject: [PATCH] chore: restyle provisioner job output format 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 f8282465a3d56..28a12cdfe56c4 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 = "✘" + } + dur := startedAt.Sub(currentStageStartedAt).Milliseconds() + if dur < 0 { + dur = 0 } - _, _ = fmt.Fprintf(writer, prefix+mark.String()+DefaultStyles.Placeholder.Render(" %s [%dms]")+"\n", currentStage, startedAt.Sub(currentStageStartedAt).Milliseconds()) + _, _ = 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 ccbff650d2e09..b75727dbb73cf 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)