LoaderWidget
LoaderWidget displays an animated spinner with a text message.
The animation advances automatically via the event loop.
When to Use
Use LoaderWidget to indicate that a background operation is in
progress: loading data, waiting for a network response, processing
files, etc. For operations that can be cancelled, use
CancellableLoaderWidget. For operations with measurable progress,
use ProgressBarWidget.
Basic Usage
1 2 3 4
use Symfony\Component\Tui\Widget\LoaderWidget;
$loader = new LoaderWidget('Fetching data...');
$tui->add($loader);
The loader starts automatically on construction. Stop it when the operation completes:
1
$loader->stop();
Call start() to restart the animation after stopping it.
Message
Update the message while the loader is running:
1
$loader->setMessage('Processing items...');
Spinner Styles
Eight built-in spinner styles are available: dots (default),
line, bounce, pulse, bar, shade, arc and
circle.
Switch the style with setSpinner():
1
$loader->setSpinner('pulse');
Register a custom spinner with addSpinner():
1 2
LoaderWidget::addSpinner('arrows', ['←', '↑', '→', '↓']);
$loader->setSpinner('arrows');
Animation Speed
Control the frame rate with setIntervalMs():
1
$loader->setIntervalMs(120); // slower animation
The default interval is 80 ms.
Finished Indicator
Show a static character when the loader stops instead of hiding it entirely:
1 2
$loader->setFinishedIndicator('✓');
$loader->stop(); // displays "✓ Fetching data..."
Styleable Elements
LoaderWidget exposes two styleable elements:
spinner: the animated character.message: the text next to the spinner.
Events
LoaderWidget does not emit any events. Check its state with
isRunning().