From 591cd4586c0199e9041b917baa342b42fea241ac Mon Sep 17 00:00:00 2001 From: freek Date: Wed, 24 Nov 2021 10:28:30 +0100 Subject: [PATCH 1/2] wip --- docs/usage/framework-agnostic-php-project.md | 15 +++++++++++-- docs/usage/reference.md | 1 + src/Payloads/SeparatorPayload.php | 12 +++++++++++ src/Ray.php | 8 +++++++ tests/RayTest.php | 8 +++++++ .../RayTest__it_can_send_a_separator__1.json | 21 +++++++++++++++++++ 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/Payloads/SeparatorPayload.php create mode 100644 tests/__snapshots__/RayTest__it_can_send_a_separator__1.json diff --git a/docs/usage/framework-agnostic-php-project.md b/docs/usage/framework-agnostic-php-project.md index 05191cbd..e64845cc 100644 --- a/docs/usage/framework-agnostic-php-project.md +++ b/docs/usage/framework-agnostic-php-project.md @@ -58,6 +58,19 @@ ray(['John', 'Paul', 'George', 'Ringo'])->label('Beatles'); ![screenshot](/docs/ray/v1/images/label.png) +### Showing a separator + +Another way to visually separate items in Ray, is to call `seperator`. + +```php +ray('first item'); + +ray()->separator(); + +ray('second item'); +``` + +![screenshot](/docs/ray/v1/images/separator.png) ### Creating a new screen @@ -193,7 +206,6 @@ foreach (range(1, 10) as $i) { If the argument passed to `limit()` is a negative number or zero, limiting is disabled. - ### Using a rate limiter A rate limiter can help to reduce the amount of sent messages. This would avoid spamming the desktop app, which can be helpful when using Ray in loops. @@ -213,7 +225,6 @@ Ray::rateLimiter()->clear(); A message to the desktop app will be sent once to notify the user the rate limit has been reached. - ### Sending a payload once To only send a payload once, use the `once` function. This is useful for debugging loops. diff --git a/docs/usage/reference.md b/docs/usage/reference.md index f536fbc1..a8f1955b 100644 --- a/docs/usage/reference.md +++ b/docs/usage/reference.md @@ -75,6 +75,7 @@ To display something in Ray use the `ray()` function. It accepts everything: str | `ray()->rateLimiter()->clear()` | Clears the rate limits | | `ray()->raw($value)` | Send raw output of a value to Ray without fancy formatting | | `ray(…)->red()` | Output in red | +| `ray()->separator()` | Add a visual separator | | `ray()->showApp()` | Bring the app to the foreground | | `ray(…)->small()` | Output text smaller | | `ray()->table($array, $label)` | Format an associative array with optional label | diff --git a/src/Payloads/SeparatorPayload.php b/src/Payloads/SeparatorPayload.php new file mode 100644 index 00000000..0da1ec56 --- /dev/null +++ b/src/Payloads/SeparatorPayload.php @@ -0,0 +1,12 @@ +sendRequest($payload); + } + public function html(string $html = ''): self { $payload = new HtmlPayload($html); diff --git a/tests/RayTest.php b/tests/RayTest.php index d6e6372c..f724d614 100644 --- a/tests/RayTest.php +++ b/tests/RayTest.php @@ -1286,6 +1286,14 @@ public function it_can_dump_a_string_with_a_global_function_name() $this->assertMatchesOsSafeSnapshot($this->client->sentPayloads()); } + /** @test */ + public function it_can_send_a_separator() + { + $this->ray->send('separator'); + + $this->assertMatchesOsSafeSnapshot($this->client->sentPayloads()); + } + protected function getNewRay(): Ray { return Ray::create($this->client, 'fakeUuid'); diff --git a/tests/__snapshots__/RayTest__it_can_send_a_separator__1.json b/tests/__snapshots__/RayTest__it_can_send_a_separator__1.json new file mode 100644 index 00000000..d0a34a5d --- /dev/null +++ b/tests/__snapshots__/RayTest__it_can_send_a_separator__1.json @@ -0,0 +1,21 @@ +[ + { + "uuid": "fakeUuid", + "payloads": [ + { + "type": "log", + "content": { + "values": [ + "separator" + ] + }, + "origin": { + "file": "\/tests\/RayTest.php", + "line_number": "xxx", + "hostname": "fake-hostname" + } + } + ], + "meta": [] + } +] From 642ff80e93b609d8543241731fb3e9b2f76facbf Mon Sep 17 00:00:00 2001 From: freekmurze Date: Wed, 24 Nov 2021 09:29:11 +0000 Subject: [PATCH 2/2] Fix styling --- src/Payloads/SeparatorPayload.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Payloads/SeparatorPayload.php b/src/Payloads/SeparatorPayload.php index 0da1ec56..721329e7 100644 --- a/src/Payloads/SeparatorPayload.php +++ b/src/Payloads/SeparatorPayload.php @@ -7,6 +7,5 @@ class SeparatorPayload extends Payload public function getType(): string { return 'separator'; - } }