Class Spinner
Single-line animated spinner. Use once via
using var s = Spinner.Show("loading…"); — disposing stops the
animation, clears the spinner line, and emits a newline.
public sealed class Spinner : IDisposable
- Inheritance
-
Spinner
- Implements
- Inherited Members
Remarks
Without ANSI support (output redirected, NO_COLOR, dumb
terminal) the spinner does not animate: it writes the label once on
Show(string, SpinnerStyle, Color?, int) and a newline on Stop(). This keeps
log files free of dozens of overwrite frames.
The spinner owns its line for its lifetime — concurrent writes from other code while the spinner is active will be clobbered by the next repaint. Either route writes through Update(string) / Stop(string?, Color?), or stop the spinner first.
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Show(string, SpinnerStyle, Color?, int)
Begin a new spinner.
public static Spinner Show(string label, SpinnerStyle style = SpinnerStyle.Pipe, Color? color = null, int msPerFrame = 80)
Parameters
labelstringText shown to the right of the animated glyph.
styleSpinnerStyleFrame set. Defaults to Pipe.
colorColor?Optional foreground color for the glyph.
msPerFrameintFrame duration in milliseconds. Clamped to ≥1.
Returns
Stop()
Stop the spinner with no final state.
public void Stop()
Stop(string?, Color?)
Stop the spinner and write a final state in place — useful for "✓ done" / "✗ failed" indications. The final label fully replaces the spinner line; bring your own glyph.
public void Stop(string? finalLabel, Color? finalColor = null)
Parameters
Update(string)
Replace the label without stopping the animation.
public void Update(string label)
Parameters
labelstring