Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/console/src/Terminal/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Integration/Console/TerminalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
});
}
}
Loading