diff --git a/src/Note.php b/src/Note.php index 4c969cd5..b2239673 100644 --- a/src/Note.php +++ b/src/Note.php @@ -29,7 +29,7 @@ public function prompt(): bool $this->state = 'submit'; - $this->output()->write($this->renderTheme()); + static::output()->write($this->renderTheme()); return true; } diff --git a/src/Prompt.php b/src/Prompt.php index fd31969b..49641bc1 100644 --- a/src/Prompt.php +++ b/src/Prompt.php @@ -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(); @@ -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; } @@ -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; @@ -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 = ''; @@ -185,7 +185,7 @@ 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]; @@ -193,7 +193,7 @@ protected function render(): void $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;