xico2k / termwind-plugin-live
Termwind 的实时插件。
dev-main
2023-03-06 16:54 UTC
Requires
- php: ^8.0
- nunomaduro/termwind: ^1.15
Requires (Dev)
- ergebnis/phpstan-rules: ^1.0
- laravel/pint: ^1.6
- mockery/mockery: ^1.5
- pestphp/pest: ^2.0.0
- phpstan/phpstan: ^1.10
- phpstan/phpstan-strict-rules: ^1.5
- rector/rector: ^0.15.19
- symfony/var-dumper: ^6.2
- thecodingmachine/phpstan-strict-rules: ^1.0
This package is auto-updated.
Last update: 2024-09-06 20:12:12 UTC
README
Termwind Live 插件
Termwind Live 插件 允许您使您的 cli 内容实时更新。
安装
需要 PHP 8.0+
使用 Composer 安装 Termwind Live 插件
composer require xico2k/termwind-plugin-live
使用方法
use function Termwind\Live\live; live(function () { static $total = 0; return sprintf('The content was refreshed %d times.', ++$total); })->refreshEvery(seconds: 1);
refreshEvery()
可以使用 refreshEvery
方法通过一定时间间隔更新内容。
可用方法
refreshEvery(milliseconds: 0, seconds: 0)
refreshEverySeconds($seconds)
refreshEveryMilliseconds($seconds)
// Seconds live(fn () => 'foo')->refreshEverySeconds(1); // or live(fn () => 'foo')->refreshEvery(seconds: 1); // Milliseconds live(fn () => 'foo')->refreshEveryMilliseconds(250); // or live(fn () => 'foo')->refreshEvery(milliseconds: 1);
while(Closure $condition)
可以使用 while()
方法在条件为 true
时更新内容。
live(fn () => 'Loading...') ->while(fn () => $process->running());
showCursor()
和 hideCursor()
可以使用 showCursor()
和 hideCursor()
方法在您的 cli 上显示/隐藏光标。
live('Loading...') ->hideCursor() ->while(fn () => $process->running()) ->showCursor();
clear()
可以使用 clear()
方法清除实时输出。
live('Loading...') ->while(fn () => $process->running()) ->clear();
RefreshEvent
RefreshEvent
被传递到 Closure
中,并提供了一种停止执行的方式。
use Termwind\Live\Events\RefreshEvent; live(function (RefreshEvent $event) { $shouldStop = true; // Call to check something... if ($shouldStop) { $event->stop(); } return 'foo'; })->refreshEvery(seconds: 1);
Termwind Live 插件是一个开源软件,采用 MIT 许可证。