Documentation ¶
Overview ¶
Package printer provides functionality for printing job events and progress. It offers different types of printers to handle various output formats and requirements.
Index ¶
- Constants
- Variables
- func PrintError(cmd *cobra.Command, err error)
- func PrintEvent(cmd *cobra.Command, event models.Event)
- func PrintWarning(cmd *cobra.Command, msg string)
- func SummariseExecutions(executions []*models.Execution) map[string][]string
- func SummariseHistoryEvents(history []*models.JobHistory) []models.Event
- type FishSpinner
- type JobProgressPrinter
- type LineMessage
- type SpinActionType
- type Spinner
- type SpinnerStopReason
Constants ¶
const ( TickerUpdateFrequency = 50 * time.Millisecond SpinnerFormatDurationDefault = 30 * time.Millisecond TextLineupSpacing = 10 )
const ( SpacerText = " ... " ReverseText = " ... " )
const ( StatusNone = " " StatusDone = "done ✅" StatusWait = "wait ⏳" StatusErr = "err ❌" )
const ( WidthDots = 16 WidthStatus = 6 // Don't left pad the timer column because we want it to be left aligned. WidthTimer = 0 )
Variables ¶
var SpinnerEmoji = [...]string{"🐟", "🐠", "🐡"}
Functions ¶
func PrintError ¶ added in v1.5.0
func PrintWarning ¶ added in v1.5.0
func SummariseExecutions ¶ added in v1.5.0
Groups the executions in the job state, returning a map of printable messages to node(s) that generated that message.
func SummariseHistoryEvents ¶ added in v1.5.0
func SummariseHistoryEvents(history []*models.JobHistory) []models.Event
Types ¶
type FishSpinner ¶ added in v1.5.0
type FishSpinner struct {
// contains filtered or unexported fields
}
FishSpinner represents a simple fish emoji spinner. It provides a visual indicator of ongoing processing while allowing concurrent event printing.
The FishSpinner operates in its own goroutine, continuously updating and printing the spinner animation. However, it's designed to work in conjunction with an event printer, which may need to write to the console periodically.
To prevent the spinner and event printer from writing to the console simultaneously and causing overlapping output, the FishSpinner implements a synchronization mechanism:
- The event printer should call Pause() before printing a new event row. This pauses the spinner animation
- The event printer then calls clear() to remove the spinner from the console
- The event printer then prints its event row.
- After printing, the event printer should call Resume() to restart the spinner animation from where it left before pausing.
This synchronization ensures that the spinner and event printer's outputs don't interfere with each other, maintaining clean and readable console output.
func NewFishSpinner ¶ added in v1.5.0
func NewFishSpinner(writer io.Writer) *FishSpinner
NewFishSpinner creates a new FishSpinner
func (*FishSpinner) Clear ¶ added in v1.5.0
func (s *FishSpinner) Clear()
Clear removes the spinner from the console
func (*FishSpinner) Pause ¶ added in v1.5.0
func (s *FishSpinner) Pause()
Pause temporarily stops the spinner animation and clears its output This function is called before the event printer wants to print a new row
func (*FishSpinner) Resume ¶ added in v1.5.0
func (s *FishSpinner) Resume()
Resume restarts the spinner animation after it has been paused This function is called after the event printer has finished printing
func (*FishSpinner) Start ¶ added in v1.5.0
func (s *FishSpinner) Start()
Start begins the spinner animation
func (*FishSpinner) Stop ¶ added in v1.5.0
func (s *FishSpinner) Stop()
Stop stops the spinner animation
type JobProgressPrinter ¶ added in v1.5.0
type JobProgressPrinter struct {
// contains filtered or unexported fields
}
func NewJobProgressPrinter ¶ added in v1.5.0
func NewJobProgressPrinter(client clientv2.API, runtimeSettings *cliflags.RunTimeSettings) *JobProgressPrinter
func (*JobProgressPrinter) PrintJobProgress ¶ added in v1.5.0
func (j *JobProgressPrinter) PrintJobProgress(ctx context.Context, job *models.Job, cmd *cobra.Command) error
PrintJobProgress displays the job progress based on CLI runtime settings
type LineMessage ¶
type LineMessage struct { Message string Detail string TimerString string Waiting bool Failure bool ColumnWidths []uint8 }
func NewLineMessage ¶
func NewLineMessage(msg string, maxWidth int) LineMessage
func (*LineMessage) BlankSpinner ¶
func (f *LineMessage) BlankSpinner(col int) string
func (*LineMessage) PrintOnCancel ¶
func (f *LineMessage) PrintOnCancel() string
func (*LineMessage) PrintOnDone ¶
func (f *LineMessage) PrintOnDone() string
func (*LineMessage) PrintOnFail ¶
func (f *LineMessage) PrintOnFail() string
func (*LineMessage) SpinnerMessage ¶
func (f *LineMessage) SpinnerMessage() string
func (*LineMessage) SpinnerPrefix ¶
func (f *LineMessage) SpinnerPrefix() string
type SpinActionType ¶
type SpinActionType int
const ( SpinActionStart SpinActionType = iota SpinActionStop )
type Spinner ¶
type Spinner struct {
// contains filtered or unexported fields
}
func NewSpinner ¶
func NewSpinner(ctx context.Context, w io.Writer, maxWidth int, handleSigint bool) (*Spinner, error)
NewSpinner creates a new `Spinner` using the provided io.Writer and expecting a message of no more than `maxWidth` characters. The `maxWidth` is required to ensure that following steps in the lifetime of the spinner line up.
func (*Spinner) Done ¶
func (s *Spinner) Done(reason SpinnerStopReason)
Done stops the spinner, ignoring any errors as there is no further use for the spinner.
type SpinnerStopReason ¶
type SpinnerStopReason int
const ( StopSuccess SpinnerStopReason = iota StopFailed StopCancel )