Terminal.php 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. namespace Termwind;
  4. use Symfony\Component\Console\Terminal as ConsoleTerminal;
  5. /**
  6. * @internal
  7. */
  8. final class Terminal
  9. {
  10. /**
  11. * An instance of Symfony's console terminal.
  12. */
  13. private ConsoleTerminal $terminal;
  14. /**
  15. * Creates a new terminal instance.
  16. */
  17. public function __construct(?ConsoleTerminal $terminal = null)
  18. {
  19. $this->terminal = $terminal ?? new ConsoleTerminal;
  20. }
  21. /**
  22. * Gets the terminal width.
  23. */
  24. public function width(): int
  25. {
  26. return $this->terminal->getWidth();
  27. }
  28. /**
  29. * Gets the terminal height.
  30. */
  31. public function height(): int
  32. {
  33. return $this->terminal->getHeight();
  34. }
  35. /**
  36. * Clears the terminal screen.
  37. */
  38. public function clear(): void
  39. {
  40. Termwind::getRenderer()->write("\ec");
  41. }
  42. }