Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Enforce static calls of static methods #11

Merged
merged 1 commit into from
Jul 28, 2023
Merged
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 src/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function prompt(): bool

$this->state = 'submit';

$this->output()->write($this->renderTheme());
static::output()->write($this->renderTheme());

return true;
}
Expand Down
24 changes: 12 additions & 12 deletions src/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,30 @@ public function prompt(): mixed
{
$this->capturePreviousNewLines();

if ($this->shouldFallback()) {
if (static::shouldFallback()) {
return $this->fallback();
}

register_shutdown_function(function () {
$this->restoreCursor();
$this->terminal()->restoreTty();
static::terminal()->restoreTty();
});

$this->terminal()->setTty('-icanon -isig -echo');
static::terminal()->setTty('-icanon -isig -echo');
$this->hideCursor();
$this->render();

while (($key = $this->terminal()->read()) !== null) {
while (($key = static::terminal()->read()) !== null) {
$continue = $this->handleKeyPress($key);

$this->render();

if ($continue === false || $key === Key::CTRL_C) {
$this->restoreCursor();
$this->terminal()->restoreTty();
static::terminal()->restoreTty();

if ($key === Key::CTRL_C) {
$this->terminal()->exit();
static::terminal()->exit();
}

return $this->value();
Expand All @@ -117,8 +117,8 @@ public function newLinesWritten(): int
*/
protected function capturePreviousNewLines(): void
{
$this->newLinesWritten = method_exists($this->output(), 'newLinesWritten')
? $this->output()->newLinesWritten()
$this->newLinesWritten = method_exists(static::output(), 'newLinesWritten')
? static::output()->newLinesWritten()
: 1;
}

Expand Down Expand Up @@ -158,7 +158,7 @@ protected function render(): void
}

if ($this->state === 'initial') {
$this->output()->write($frame);
static::output()->write($frame);

$this->state = 'active';
$this->prevFrame = $frame;
Expand All @@ -171,7 +171,7 @@ protected function render(): void
// Ensure that the full frame is buffered so subsequent output can see how many trailing newlines were written.
if ($this->state === 'submit') {
$this->eraseDown();
$this->output()->write($frame);
static::output()->write($frame);

$this->prevFrame = '';

Expand All @@ -185,15 +185,15 @@ protected function render(): void
$this->moveCursor(0, $diffLine);
$this->eraseLines(1);
$lines = explode(PHP_EOL, $frame);
$this->output()->write($lines[$diffLine]);
static::output()->write($lines[$diffLine]);
$this->moveCursor(0, count($lines) - $diffLine - 1);
} elseif (count($diff) > 1) { // Re-render everything past the first change
$diffLine = $diff[0];
$this->moveCursor(0, $diffLine);
$this->eraseDown();
$lines = explode(PHP_EOL, $frame);
$newLines = array_slice($lines, $diffLine);
$this->output()->write(implode(PHP_EOL, $newLines));
static::output()->write(implode(PHP_EOL, $newLines));
}

$this->prevFrame = $frame;
Expand Down