Skip to content

Commit

Permalink
Added Console::clearScreen()
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebowczyk committed Oct 9, 2024
1 parent 347390b commit 146708b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion examples/A02_Advanced/PartialUpdates/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Cognesy\Instructor\Enums\Mode;
use Cognesy\Instructor\Events\Event;
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Utils\Cli\Console;

class UserRole
{
Expand All @@ -43,7 +44,7 @@ class UserDetail
// This function will be called every time a new token is received
function partialUpdate($partial) {
// Clear the screen and move the cursor to the top
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
Console::clearScreen();

// Display the partial object
dump($partial);
Expand Down
3 changes: 2 additions & 1 deletion examples/A02_Advanced/Streaming/run.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Cognesy\Instructor\Enums\Mode;
use Cognesy\Instructor\Instructor;
use Cognesy\Instructor\Utils\Cli\Console;

class UserRole
{
Expand All @@ -40,7 +41,7 @@ class UserDetail
// This function will be called every time a new token is received
function partialUpdate($partial) {
// Clear the screen and move the cursor to the top
echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
Console::clearScreen();

// Display the partial object
dump($partial);
Expand Down
5 changes: 5 additions & 0 deletions src/Utils/Cli/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public static function println(string $message, string|array $color = ''): void
print(self::color($color, $message) . PHP_EOL);
}

public static function clearScreen(): void {
print("\033[2J\033[;H");
//echo chr(27).chr(91).'H'.chr(27).chr(91).'J';
}

public static function columns(array $columns, int $maxWidth): string {
$maxWidth = max($maxWidth, 80);
$message = '';
Expand Down

0 comments on commit 146708b

Please sign in to comment.