MCPcopy
hub / github.com/pterm/pterm / Start

Method Start

spinner_printer.go:148–179  ·  view source on GitHub ↗

Start the SpinnerPrinter.

(text ...any)

Source from the content-addressed store, hash-verified

146
147// Start the SpinnerPrinter.
148func (s SpinnerPrinter) Start(text ...any) (*SpinnerPrinter, error) {
149 s.IsActive = true
150 s.startedAt = time.Now()
151 activeSpinnerPrinters = append(activeSpinnerPrinters, &s)
152
153 if len(text) != 0 {
154 s.Text = Sprint(text...)
155 }
156
157 go func() {
158 for s.IsActive {
159 for _, seq := range s.Sequence {
160 if !s.IsActive {
161 continue
162 }
163 if RawOutput {
164 time.Sleep(s.Delay)
165 continue
166 }
167
168 var timer string
169 if s.ShowTimer {
170 timer = " (" + time.Since(s.startedAt).Round(s.TimerRoundingFactor).String() + ")"
171 }
172 Fprinto(s.Writer, s.Style.Sprint(seq)+" "+s.MessageStyle.Sprint(s.Text)+s.TimerStyle.Sprint(timer))
173 s.currentSequence = seq
174 time.Sleep(s.Delay)
175 }
176 }
177 }()
178 return &s, nil
179}
180
181// Stop terminates the SpinnerPrinter immediately.
182// The SpinnerPrinter will not resolve into anything.

Callers 2

GenericStartMethod · 0.95

Calls 4

SprintFunction · 0.85
FprintoFunction · 0.85
SprintMethod · 0.65
StringMethod · 0.45

Tested by 1