This pull request allows to make a particular section of the console dynamic. Here is an example:
use function Termwind\{live};
live(function () {
static $counter = 0;
$counter++;
return '<div class="m-1">
<span class="pl-1 pr-2 bg-blue-300">My counter</span>
<span class="ml-1">' . $counter . '</span>
</div>';
})->refreshEvery(seconds: 1);
Will render the following:
In addition, you may control when the refresh should stop, by calling the RefreshEvent::stop
method.
live(function (RefreshEvent $event) {
return $event->stop();
})->refreshEvery(seconds: 1);
Finally, if you wish to control, when to render, clear, or refresh, you may control the flow using these methods:
use function Termwind\{live};
$live = live(fn () => 'html');
$live->render(); // Re-runs the given closure, and renders its output.
$live->clear(); // Removes all previous rendered html.
$live->refresh(); // Refreshes the previous rendered html.
$live->refreshEvery($seconds); // Refreshes the previous rendered html, every X amount of seconds.