From e72315710136ee5efc11c3f21187042e8d79e92a Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 24 Jul 2026 09:50:18 +0200 Subject: [PATCH] wip --- packages/console/src/Terminal/Terminal.php | 2 +- tests/Integration/Console/TerminalTest.php | 41 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/console/src/Terminal/Terminal.php b/packages/console/src/Terminal/Terminal.php index 186b862fdd..4783e3189d 100644 --- a/packages/console/src/Terminal/Terminal.php +++ b/packages/console/src/Terminal/Terminal.php @@ -175,7 +175,7 @@ private function resetInitialCursor(): void if ($requiredHeight > $availableHeight) { $this->initialCursor->setPosition(new Point( x: $this->initialCursor->getPosition()->x, - y: $this->height - $requiredHeight, + y: max(0, $this->height - $requiredHeight), )); } } diff --git a/tests/Integration/Console/TerminalTest.php b/tests/Integration/Console/TerminalTest.php index 5a705cbdc9..529a625143 100644 --- a/tests/Integration/Console/TerminalTest.php +++ b/tests/Integration/Console/TerminalTest.php @@ -5,7 +5,9 @@ namespace Tests\Tempest\Integration\Console; use PHPUnit\Framework\Attributes\Test; +use Tempest\Console\Components\Concerns\HasState; use Tempest\Console\Console; +use Tempest\Console\InteractiveConsoleComponent; use Tempest\Console\Terminal\Terminal; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; @@ -27,4 +29,43 @@ public function supports_tty(): void $this->assertFalse($terminal->supportsTty); }); } + + #[Test] + public function interactive_render_keeps_cursor_within_terminal_when_body_is_taller_than_terminal(): void + { + $this->console + ->withoutPrompting() + ->call(function (Console $console): void { + $terminal = new Terminal($console); + $terminal->disableTty(); + + $component = new class implements InteractiveConsoleComponent { + use HasState; + + public int $render = 0; + + public function render(Terminal $terminal): string + { + $this->render += 1; + + return implode(PHP_EOL, array_map( + fn (int $line): string => "render {$this->render} line {$line}", + range(1, 40), + )); + } + + public function renderFooter(Terminal $terminal): ?string + { + return null; + } + + public function setErrors(array $errors): self + { + return $this; + } + }; + + $this->assertGreaterThanOrEqual(0, $terminal->cursor->getPosition()->y); + }); + } }