Skip to content

Commit 467b0a1

Browse files
authored
chore: restyle provisioner job output format (#8106)
Reduce colors and formatting to reduce bugs and increase UNIX-feel.
1 parent 823127e commit 467b0a1

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

cli/cliui/provisionerjob.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,33 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
6363
var (
6464
currentStage = "Queued"
6565
currentStageStartedAt = time.Now().UTC()
66-
didLogBetweenStage = false
6766

6867
errChan = make(chan error, 1)
6968
job codersdk.ProvisionerJob
7069
jobMutex sync.Mutex
7170
)
7271

7372
printStage := func() {
74-
_, _ = fmt.Fprintf(writer, DefaultStyles.Prompt.Render("⧗")+"%s\n", DefaultStyles.Field.Render(currentStage))
73+
_, _ = fmt.Fprintf(writer, "==> ⧗ %s\n", currentStage)
7574
}
7675

7776
updateStage := func(stage string, startedAt time.Time) {
7877
if currentStage != "" {
79-
prefix := ""
80-
if !didLogBetweenStage {
81-
prefix = "\033[1A\r"
82-
}
83-
mark := DefaultStyles.Checkmark
78+
mark := "✔"
8479
if job.CompletedAt != nil && job.Status != codersdk.ProvisionerJobSucceeded {
85-
mark = DefaultStyles.Crossmark
80+
mark = "✘"
81+
}
82+
dur := startedAt.Sub(currentStageStartedAt).Milliseconds()
83+
if dur < 0 {
84+
dur = 0
8685
}
87-
_, _ = fmt.Fprintf(writer, prefix+mark.String()+DefaultStyles.Placeholder.Render(" %s [%dms]")+"\n", currentStage, startedAt.Sub(currentStageStartedAt).Milliseconds())
86+
_, _ = fmt.Fprintf(writer, "=== %s %s [%dms]\n", mark, currentStage, dur)
8887
}
8988
if stage == "" {
9089
return
9190
}
9291
currentStage = stage
9392
currentStageStartedAt = startedAt
94-
didLogBetweenStage = false
9593
printStage()
9694
}
9795

@@ -129,7 +127,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
129127
return
130128
}
131129
}
132-
_, _ = fmt.Fprintf(writer, "\033[2K\r\n"+DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n")
130+
_, _ = fmt.Fprintf(writer, DefaultStyles.FocusedPrompt.String()+DefaultStyles.Bold.Render("Gracefully canceling...")+"\n\n")
133131
err := opts.Cancel()
134132
if err != nil {
135133
errChan <- xerrors.Errorf("cancel: %w", err)
@@ -222,10 +220,7 @@ func ProvisionerJob(ctx context.Context, writer io.Writer, opts ProvisionerJobOp
222220
jobMutex.Unlock()
223221
continue
224222
}
225-
_, _ = fmt.Fprintf(logOutput, "%s %s\n", DefaultStyles.Placeholder.Render(" "), output)
226-
if !opts.Silent {
227-
didLogBetweenStage = true
228-
}
223+
_, _ = fmt.Fprintf(logOutput, "%s\n", output)
229224
jobMutex.Unlock()
230225
}
231226
}

cmd/cliui/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func main() {
272272
},
273273
})
274274

275-
err := root.Invoke(os.Args[1:]...).Run()
275+
err := root.Invoke(os.Args[1:]...).WithOS().Run()
276276
if err != nil {
277277
_, _ = fmt.Println(err.Error())
278278
os.Exit(1)

0 commit comments

Comments
 (0)