From 2e6c7ad3bc4b6063860388dd202781859eeaf883 Mon Sep 17 00:00:00 2001 From: thgs Date: Sun, 30 Jul 2023 16:37:42 +0100 Subject: [PATCH] wip --- examples/terminal-attributes.php | 36 +++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/examples/terminal-attributes.php b/examples/terminal-attributes.php index 03b9133..3167fde 100644 --- a/examples/terminal-attributes.php +++ b/examples/terminal-attributes.php @@ -3,6 +3,8 @@ use Aspectus\Terminal\Event\InputEvent; use Aspectus\Terminal\Xterm; use Revolt\EventLoop; +use function Amp\async; +use function Amp\delay; require \dirname(__DIR__) . '/vendor/autoload.php'; @@ -30,24 +32,20 @@ function () use ($xterm) { // boot ->setPrivateModeSaveCursorAndEnterAlternateScreenBuffer() ->hideCursor() + ->moveCursorTo(10, 15) + ->write("Resize your terminal") ->flush() ; -EventLoop::repeat(1, function () use ($xterm, $primary, $secondary) { - $xterm - // set colors - ->bgBlue() - ->brightYellow() - ->eraseAll(); - +$update = function () use ($xterm, $primary, $secondary) { $view = [ // Primary 'Terminal ID' => $primary->terminalId, 'Capabilities' => "\n\t" . implode( - " ", - // only first letter for when its running on xterm - array_map(fn ($capability) => substr($capability, 0, 1), $primary->capabilities) - ), + " ", + // only first letter for when its running on xterm + array_map(fn ($capability) => substr($capability, 0, 1), $primary->capabilities) + ), // Secondary 'Type' => $secondary->type, @@ -79,6 +77,11 @@ function () use ($xterm) { [11, 40], ]; + $xterm + ->bgBlue() + ->brightYellow() + ->eraseAll(); + $i = 0; foreach ($view as $title => $data) { $element = str_pad($title . ' ', 25, '.') . ' : ' . $data; @@ -86,7 +89,7 @@ function () use ($xterm) { ->moveCursorTo(...$lines[$i++]) ->write($element); } - // + // $xterm ->moveCursorTo(15, 10) ->blink() @@ -94,6 +97,15 @@ function () use ($xterm) { ->normal() ->flush() ; +}; + +async($update); +async(function () use (&$update) { + delay(1); + if ($update !== null) { + $update(); + } }); +EventLoop::onSignal(\SIGWINCH, $update); EventLoop::run();