TextPrompt.php 828 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace Laravel\Prompts;
  3. class TextPrompt extends Prompt
  4. {
  5. use Concerns\TypedValue;
  6. /**
  7. * Create a new TextPrompt instance.
  8. */
  9. public function __construct(
  10. public string $label,
  11. public string $placeholder = '',
  12. public string $default = '',
  13. public bool|string $required = false,
  14. public mixed $validate = null,
  15. public string $hint = '',
  16. ) {
  17. $this->trackTypedValue($default);
  18. }
  19. /**
  20. * Get the entered value with a virtual cursor.
  21. */
  22. public function valueWithCursor(int $maxWidth): string
  23. {
  24. if ($this->value() === '') {
  25. return $this->dim($this->addCursor($this->placeholder, 0, $maxWidth));
  26. }
  27. return $this->addCursor($this->value(), $this->cursorPosition, $maxWidth);
  28. }
  29. }