Skip to content

Commit

Permalink
summary - suppress spinner if noColor is true
Browse files Browse the repository at this point in the history
This behavior is consistent with how html-report behaves, and
is desireable for CI environments such as GitHub Actions
where the spinner output won't look near as pretty.
  • Loading branch information
jzweifel authored and daveshanley committed Jul 30, 2024
1 parent 34bab3e commit d2b3d1b
Showing 1 changed file with 35 additions and 24 deletions.
59 changes: 35 additions & 24 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,24 @@ func GetSummaryCommand() *cobra.Command {
}

listenForUpdates := func(updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) {
spinner, _ := pterm.DefaultSpinner.Start("starting work.")

spinner.InfoPrinter = &pterm.PrefixPrinter{
MessageStyle: &pterm.Style{pterm.FgLightCyan},
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightMagenta},
Text: " SPEC ",
},
}
spinner.SuccessPrinter = &pterm.PrefixPrinter{
MessageStyle: &pterm.Style{pterm.FgLightCyan},
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightCyan},
Text: " DONE ",
},
var spinner *pterm.SpinnerPrinter
if !noColorFlag {
spinner, _ := pterm.DefaultSpinner.Start("starting work.")

spinner.InfoPrinter = &pterm.PrefixPrinter{
MessageStyle: &pterm.Style{pterm.FgLightCyan},
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightMagenta},
Text: " SPEC ",
},
}
spinner.SuccessPrinter = &pterm.PrefixPrinter{
MessageStyle: &pterm.Style{pterm.FgLightCyan},
Prefix: pterm.Prefix{
Style: &pterm.Style{pterm.FgBlack, pterm.BgLightCyan},
Text: " DONE ",
},
}
}

var warnings []string
Expand All @@ -87,20 +90,26 @@ func GetSummaryCommand() *cobra.Command {
select {
case update, ok := <-updateChan:
if ok {
if !update.Completed {
spinner.UpdateText(update.Message)
} else {
spinner.Info(update.Message)
if !noColorFlag {
if !update.Completed {
spinner.UpdateText(update.Message)
} else {
spinner.Info(update.Message)
}
}
if update.Warning {
warnings = append(warnings, update.Message)
}
} else {
if !failed {
spinner.Success("completed")
fmt.Println()
if !noColorFlag {
spinner.Success("completed")
fmt.Println()
}
} else {
spinner.Fail("failed to complete. sorry!")
if !noColorFlag {
spinner.Fail("failed to complete. sorry!")
}
}
if len(warnings) > 0 {
pterm.Warning.Print("warnings reported during processing")
Expand All @@ -123,8 +132,10 @@ func GetSummaryCommand() *cobra.Command {
}
case err := <-errorChan:
if err.Fatal {
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
spinner.Stop()
if !noColorFlag {
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
spinner.Stop()
}
} else {
warnings = append(warnings, err.Message)
}
Expand Down

0 comments on commit d2b3d1b

Please sign in to comment.