prompts icon indicating copy to clipboard operation
prompts copied to clipboard

Nested Foreground Element in Laravel Prompts select Title Renders Incorrectly

Open imakeinternet opened this issue 8 months ago • 1 comments

Laravel Prompts Version

0.3.5

Laravel Version

12.7.2

PHP Version

8.2.27

Operating System & Version

macOS 14.7.4

Terminal Application

zsh

Description

When using Laravel Prompts' select() method with a nested foreground (<fg> tag) element in the title, the prompt title renders incorrectly.

Steps to Reproduce:

Using the following code produces the issue:

$action = select("<fg=green>Your action, <fg=yellow>{$this->user->name}</>?</>", $actionOptions);

This renders incorrectly:

Image

However, when using the following code (without nested foreground elements), it renders correctly:

$action = select("<fg=green>Your action, {$this->user->name}?</>", $actionOptions);

This renders correctly:

Image

Expected Behavior: Nested foreground elements should render correctly within the select title.

Actual Behavior: Nested foreground elements cause incorrect rendering.

Additional Information:

  • Laravel Prompts is being used within Laravel v12.7.2
  • Issue reproducible consistently with nested tags

Suggested Fix: Handle nested foreground formatting correctly in the prompt renderer or clarify limitations in the documentation if nested formatting isn't supported.

Steps To Reproduce

  1. Create a new Laravel project or use an existing Laravel 12.7.2 installation.
  2. Within a Laravel Command or Controller, include the following code snippet:
$actionOptions = ['Attack', 'Run', 'Mighty Blow (Deal 2x damage with a powerful strike)'];

$action = select("<fg=green>Your action, <fg=yellow>UserName</>?</>", $actionOptions);
  1. Run the Laravel command or controller action that executes this code.
  2. Observe the rendering of the prompt title in the terminal.

imakeinternet avatar Apr 06 '25 03:04 imakeinternet

I also know that I can accomplish what I need using the following line of code:

$action = select("<fg=green>Your action,</> <fg=yellow>{$this->user->name}</><fg=green>?</>", $actionOptions);

However, it would be a nice quality of life improvement to be able to nest tags, so you don't have to close and reopen them each time you change colors. Nesting works very well with info and other prompts, so I hope this can be resolved for the select prompt as well.

imakeinternet avatar Apr 06 '25 03:04 imakeinternet