Skip to content

Commit

Permalink
Enforce static calls of static methods (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Jul 28, 2023
1 parent c8f4f7c commit 079d044
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
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

0 comments on commit 079d044

Please sign in to comment.