Giter Club home page Giter Club logo

prompts's Introduction

Laravel Prompts

Build Status Total Downloads Latest Stable Version License

Introduction

Laravel Prompts is a PHP package for adding beautiful and user-friendly forms to your command-line applications, with browser-like features including placeholder text and validation.

Laravel Prompts is perfect for accepting user input in your Artisan console commands, but it may also be used in any command-line PHP project.

Official Documentation

Documentation for Laravel Prompts can be found on the Laravel website.

Contributing

Thank you for considering contributing to Laravel Prompts! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Laravel Prompts is open-sourced software licensed under the MIT license.

prompts's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prompts's Issues

Prompts does not check for a TTY

Laravel Prompts Version

0.1.6

Laravel Version

10.22.0

PHP Version

8.2.10

Operating System & Version

Linux 6.4.6

Terminal Application

N/A, this is about TTYless enviroments and thus no terminal

Description

Prompts does zero checking if standard input is a tty. Without an interactive tty, which can be caused running commands from cron or in Docker without allocating one, this causes stty here to fail with stty: standard input: Not a tty. Since there is zero checks to see if this was successful or checking that it's on a tty separately, the code always assumes it is on a tty. When this while loop is entered, there are no time out checks to break out of the loop, nor is there a there something to slow it down since fread(STDIN, 1024) here instantly returns zero length string with out a tty (assuming nothing has been piped in there, or has otherwise been drained).

This has the following consequences, assuming that scheduled commands in cron trigger this, 100% CPU thread utilization per instance started and slow memory exhaustion as concurrently running commands pile up.

There are a few ways I can see fixing this, from detecting the lack of a TTY & throwing an exception to end everything, to accepting default options. My assumption is detect and throw is the better one, but I'm happy to be proven wrong.

Steps To Reproduce

  1. Add a command that uses Illuminate\Console\ConfirmableTrait to the scheduler in Laravel, while forgetting to set --force for production
    • Alternatively, upgrade a package you already have a scheduled command for that migrated to using laravel/prompts, and not realize the consequences that change causes.
  2. Wait for schedule to execute the command without a TTY.
    • Alternatively, you can run a command in your shell this way to execute it without a TTY attached: (setsid php artisan activitylog:clean) </dev/null
    • Yes, the parentheses are needed, use of the subshell avoids setsid forking and going into the background, and the /dev/null redirect is to remove keyboard input, like it would be while cron runs.
  3. Profit!

`Search` function in small width of terminal

Laravel Prompts Version

0.1.0

Laravel Version

10.16.1

PHP Version

8.2

Operating System & Version

Linux

Terminal Application

Terminal of vs code and simple Terminal

Description

If I open the terminal from vs code and press the up and down arrow then it is made a new search prompt.

In my linux terminal works fine.

prompt_issue.mp4

Steps To Reproduce

I just install laravel application and make a simple command

Number 0 key in text field causes 'Uninitialized string offset 0' exemption in TypedValue.php

Laravel Prompts Version

0.1.11

Laravel Version

8.83.27

PHP Version

8.2.11

Operating System & Version

macOS 13.0

Terminal Application

Warp

Description

When using a text() field, in Laravel 8 at least, when the zero number key is pressed, it is causing an ErrorException as shown below here vendor/laravel/prompts/src/Concerns/TypedValue.php:43. This is with or without other alpha-numeric characters, as soon as zero is pressed, the exception fires.

You can paste 0's in, it's just on keypress.

image

Steps To Reproduce

When entering text into a text() field using a keyboard, not pasting, press the zero number key and exception fires.

Usage of colors makes the right border position incorrect

Laravel Prompts Version

0.1.14

Laravel Version

10.18.0

PHP Version

8.1.14

Operating System & Version

macOS 13.5

Terminal Application

Terminal

Description

When using a color within options the right border is not aligned but shifted to the left.
So far, I noticed the issue with select, multiselect and search.
This issue seems somehow similar to #29.

As visible in the screenshot the number of chars the border is shifted seems to be related to the number of chars used to identify the color.

image

P.S.: I love the new prompts 😍

Steps To Reproduce

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use function Laravel\Prompts\select;

class Dummy extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'dummy';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Dummy command';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle(): int
    {
        select(
            'See the issue?',
            [
                'yes' => '<bg=green>yes</>',
                'no' => '<bg=red>no</>',
                'maybe' => '<bg=yellow>maybe</>',
                'dontKnow' => 'don\'t know',
            ],
        );
        return Command::SUCCESS;
    }
}

allow select/multiselect to be settable with a parameter

This doesn't work to dynamically choose whether a prompt is single or multi-select:

        $prompt_function = $data->isMultiple() ? 'multiselect' : 'select';

        $value = $prompt_function(
          label: 'Enter the ' . $data->getLabel(),
          options: $options,
        );

I assume it's something to do with how PHP functions are imported?

I think it would be useful if select() could take a 'multivalued' boolean parameter. multiselect() could remain as a shorthand for that.

Support for Laravel Console Tests

It seems like Laravel Console Tests are not supported. E.g. the function Laravel\Prompts\search seems to be just blocking the test runner.

I've tried to upgrade churchtools/changelogger to use Laravel Prompts.
Everything seems to be working fine.
However, the tests do fail / never finish execution.

E.g. this test just blocks: https://github.com/hettiger/changelogger/blob/2a795d5a42075ff32ff1d10e0976a3e067488c0f/tests/Feature/Commands/NewChangelogTest.php#L12-L33

It seems like the ->expectsQuestion('Type of change', 'New feature') call fails to provide the answer to e.g. the following prompt:

https://github.com/hettiger/changelogger/blob/2a795d5a42075ff32ff1d10e0976a3e067488c0f/app/Commands/NewCommand.php#L90-L97

Please add support for Laravel Console Tests to Laravel Prompts. That would be awesome.

composer show
$ composer show
brick/math                          0.11.0   Arbitrary-precision arithmetic library
doctrine/inflector                  2.0.8    PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/instantiator               2.0.0    A small, lightweight utility to instantiate objects in PHP without invoking their constructors
dragonmantank/cron-expression       v3.3.2   CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
filp/whoops                         2.15.3   php error handling for cool kids
graham-campbell/result-type         v1.1.1   An Implementation Of The Result Type
hamcrest/hamcrest-php               v2.0.1   This is the PHP port of Hamcrest Matchers
illuminate/bus                      v10.17.1 The Illuminate Bus package.
illuminate/cache                    v10.17.1 The Illuminate Cache package.
illuminate/collections              v10.17.1 The Illuminate Collections package.
illuminate/conditionable            v10.17.1 The Illuminate Conditionable package.
illuminate/config                   v10.17.1 The Illuminate Config package.
illuminate/console                  v10.17.1 The Illuminate Console package.
illuminate/container                v10.17.1 The Illuminate Container package.
illuminate/contracts                v10.17.1 The Illuminate Contracts package.
illuminate/events                   v10.17.1 The Illuminate Events package.
illuminate/filesystem               v10.17.1 The Illuminate Filesystem package.
illuminate/macroable                v10.17.1 The Illuminate Macroable package.
illuminate/pipeline                 v10.17.1 The Illuminate Pipeline package.
illuminate/process                  v10.17.1 The Illuminate Process package.
illuminate/support                  v10.17.1 The Illuminate Support package.
illuminate/testing                  v10.17.1 The Illuminate Testing package.
illuminate/view                     v10.17.1 The Illuminate View package.
jolicode/jolinotif                  v2.5.2   Send desktop notifications on Windows, Linux, MacOS.
laravel-zero/foundation             v10.12.0 This is a mirror from illuminate/foundation.
laravel-zero/framework              v10.1.1  The Laravel Zero Framework.
laravel/prompts                     v0.1.3
league/flysystem                    3.15.1   File storage abstraction for PHP
league/flysystem-local              3.15.0   Local filesystem adapter for Flysystem.
league/mime-type-detection          1.12.0   Mime-type detection for Flysystem
mockery/mockery                     1.6.4    Mockery is a simple yet flexible PHP mock object framework
myclabs/deep-copy                   1.11.1   Create deep copies (clones) of your objects
nesbot/carbon                       2.68.1   An API extension for DateTime that supports 281 different languages.
nikic/php-parser                    v4.16.0  A PHP parser written in PHP
nunomaduro/collision                v7.8.0   Cli error handling for console/command-line PHP applications.
nunomaduro/laravel-console-summary  v1.10.0  A Beautiful Laravel Console Summary for your Laravel/Laravel Zero commands.
nunomaduro/laravel-console-task     v1.8.0   Laravel Console Task is a output method for your Laravel/Laravel Zero commands.
nunomaduro/laravel-desktop-notifier v2.7.0   Send notifications to your desktop from your Laravel commands. An JoliNotif wrapper for Laravel 5.
nunomaduro/termwind                 v1.15.1  Its like Tailwind CSS, but for the console.
phar-io/manifest                    2.0.3    Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version                     3.2.1    Library for handling version information and constraints
phpoption/phpoption                 1.9.1    Option Type for PHP
phpunit/php-code-coverage           9.2.27   Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator           3.0.6    FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker                 3.1.1    Invoke callables with a timeout
phpunit/php-text-template           2.0.4    Simple template engine.
phpunit/php-timer                   5.0.3    Utility class for timing
phpunit/phpunit                     9.6.10   The PHP Unit Testing framework.
psr/container                       2.0.2    Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                1.0.0    Standard interfaces for event handling.
psr/log                             3.0.0    Common interface for logging libraries
psr/simple-cache                    3.0.0    Common interfaces for simple caching
ramsey/collection                   2.0.0    A PHP library for representing and manipulating collections.
ramsey/uuid                         4.7.4    A PHP library for generating and working with universally unique identifiers (UUIDs).
sebastian/cli-parser                1.0.1    Library for parsing CLI options
sebastian/code-unit                 1.0.8    Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup  2.0.3    Looks up which function or method a line of code belongs to
sebastian/comparator                4.0.8    Provides the functionality to compare PHP values for equality
sebastian/complexity                2.0.2    Library for calculating the complexity of PHP code units
sebastian/diff                      4.0.5    Diff implementation
sebastian/environment               5.1.5    Provides functionality to handle HHVM/PHP environments
sebastian/exporter                  4.0.5    Provides the functionality to export PHP variables for visualization
sebastian/global-state              5.0.6    Snapshotting of global state
sebastian/lines-of-code             1.0.3    Library for counting the lines of code in PHP source code
sebastian/object-enumerator         4.0.4    Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector          2.0.4    Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context         4.0.5    Provides functionality to recursively process PHP variables
sebastian/resource-operations       3.0.3    Provides a list of PHP built-in functions that operate on resources
sebastian/type                      3.2.1    Collection of value objects that represent the types of the PHP type system
sebastian/version                   3.0.2    Library that helps with managing the version number of Git-hosted PHP projects
symfony/console                     v6.3.2   Eases the creation of beautiful and testable command line interfaces
symfony/deprecation-contracts       v3.3.0   A generic function and convention to trigger deprecation notices
symfony/error-handler               v6.3.2   Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher            v6.3.2   Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts  v3.3.0   Generic abstractions related to dispatching event
symfony/finder                      v6.3.3   Finds files and directories via an intuitive fluent interface
symfony/polyfill-ctype              v1.27.0  Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme      v1.27.0  Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-normalizer    v1.27.0  Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring           v1.27.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php80              v1.27.0  Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/process                     v6.3.2   Executes commands in sub-processes
symfony/service-contracts           v3.3.0   Generic abstractions related to writing services
symfony/string                      v6.3.2   Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation                 v6.3.3   Provides tools to internationalize your application
symfony/translation-contracts       v3.3.0   Generic abstractions related to translation
symfony/var-dumper                  v6.3.3   Provides mechanisms for walking through any arbitrary PHP variable
symfony/yaml                        v5.4.23  Loads and dumps YAML files
theseer/tokenizer                   1.2.1    A small library for converting tokenized PHP source code into XML and potentially other formats
vlucas/phpdotenv                    v5.5.0   Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
voku/portable-ascii                 2.0.1    Portable ASCII library - performance optimized (ascii) string functions for php.
webmozart/assert                    1.11.0   Assertions to validate method input/output with nice error messages.

The suggest prompt with a required flag not working as expected

Laravel Prompts Version

0.1.1

Laravel Version

10.14.1

PHP Version

8.1.2

Operating System & Version

Ubuntu 22.04.2 LTS

Terminal Application

VScode

Description

Hi,

It seems like a weird interaction between the "suggest" prompt and the required flag where the first time you select an option you get the "Required" error.

Steps To Reproduce

$database = suggest(
    label: 'Name of the database to dump',
    options: $this->databases(),
    required: true
);
  1. Press the down arrow key to choose a database from the list.
  2. Press ENTER to select the database
  3. Get the "Required" error message
  4. Pressing ENTER again clears the error and make the actual selection.

Entering 0 on text input crashes

Laravel Prompts Version

0.1.0

Laravel Version

10.16.1

PHP Version

8.2.8

Operating System & Version

macOS 13.4.1

Terminal Application

iTerm

Description

There seems to be a problem with Laravel\Prompts\text and entering 0.

Config of the input in question:

$description = text(
    'Describe the change.',
    'Upgrade Laravel to v10'
);

Error on entering 0:

 β”Œ Describe the change. ────────────────────────────────────────┐
 β”‚ Upgrade Laravel to v10                                       β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


   ErrorException

  Uninitialized string offset 0

  at vendor/laravel/prompts/src/Concerns/TypedValue.php:43
     39β–•             $this->cursorPosition = strlen($this->typedValue);
     40β–•         }
     41β–•
     42β–•         $this->on('key', function ($key) use ($submit) {
  ➜  43β–•             if ($key[0] === "\e") {
     44β–•                 match ($key) {
     45β–•                     Key::LEFT => $this->cursorPosition = max(0, $this->cursorPosition - 1),
     46β–•                     Key::RIGHT => $this->cursorPosition = min(strlen($this->typedValue), $this->cursorPosition + 1),
     47β–•                     Key::DELETE => $this->typedValue = substr($this->typedValue, 0, $this->cursorPosition).substr($this->typedValue, $this->cursorPosition + 1),

      +5 vendor frames
  6   app/Console/Commands/ChangelogCommand.php:69

  7   app/Console/Commands/ChangelogCommand.php:51
      App\Console\Commands\ChangelogCommand::create()

Steps To Reproduce

copy my input and enter 0

Accent Caracter

Laravel Prompts Version

Latest

Laravel Version

Latest

PHP Version

8.1.21

Operating System & Version

macOS 13.4.1

Terminal Application

iTerm2 3.4.19

Description

I don't know if this is really a bug, but for cases where we have words with accents, when erasing the word, a ball symbol like this one remains in the terminal, which also affects the layout of the layout on the right:

CleanShot 2023-08-01 at 7 15 08

For example: Pagination in Portuguese πŸ‘‰ Paginação

CleanShot 2023-08-01 at 7 15 44

Steps To Reproduce

Try using a word that contains accents and then delete it.

can it add support for laravel 9 and 8 ?

i see in composer.json require "illuminate/collections": "^10.0" which is support only for laravel 10, i have an old laravel apps using version 8 and 9, i want using this prompts package πŸ˜„

Allow spinners to be marked as "done" and persist in the UI.

When running a task with multiple spinners that are over with particularly quickly, only one spinner instance is shown, but the message: argument changes:

CleanShot 2023-09-27 at 11 11 10

This is great, but if multiple tasks run quickly, the spinner simply appears to keep the text from the first instance that was around long enough to render the message:

CleanShot 2023-09-27 at 11 12 41

Of course, you can add info calls to intersperse them:

CleanShot 2023-09-27 at 11 14 32

But the spinner disappears and just leaves the info messages in one big "dump".

Suggestion: Persistent / Completed spinner.

When a spinner completes it's callback, the spinner persists in the UI, but with a checkmark next to it, or, if it failed, a red cross?

This way, you get: predictable output for tasks and can see previous completions.

I would suggest a persist argument to the class:

spin(
  callback: fn () => $this->doSomething(),
  message: 'Calling the API',
  persist: true,
);

Please excuse the bad photoshop next...

CleanShot 2023-09-27 at 11 28 45@2x

Something like this?

Would love to know your thoughts.

Allow easy selection of output interface (stdin/stderr)

Scenario: You have a command that outputs raw data (like json or csv) to the console, and it uses laravel/prompts. You want to save the output to a file, so you run php artisan some:command > path/to/file.json.
Unfortunately the prompt is using stdout, so it gets sent to the file and you don't see anything in the console.

I figured out a workaround that makes the prompt use stderr:

$output = $this->getOutput()->getOutput();
if ($output instanceof ConsoleOutputInterface) {
    Prompt::setOutput($output->getErrorOutput());
}

It works great, but it would be nice if there was an easier and more intuitive way of doing it. Maybe an optional argument that allows you to pass an OutputInterface, or a static Prompt::stderr() method. And maybe consider using stderr by default in the next major release, unless there are any drawbacks that I'm not aware of.

No output after `Artisan::call()` command

Laravel Prompts Version

0.1.7

Laravel Version

10.23.1

PHP Version

8,2.10

Operating System & Version

Arch Linux (Stable Kernel)/Ubuntu 22.04

Terminal Application

ZSH

Description

Good day,
asked on Discord yesterday and got said to open an issue.

I migrated the Migration Console Command in my application to Prompts, the informational message intro is shown, and the confirm question too, but after this nothing else, until the command is done, for local environment this does work, but on staging/production it doesnt, as some parts need manual input there.

Maybe this video shows what I mean:
https://github.com/laravel/prompts/assets/695535/0fb409e9-4b61-4f7a-bb65-eeae6728c929

Even if I remove the spin (I just tested something with it, as it is not documented), nothing else is shown, the full code of my migration can be found in this Gist:
https://gist.github.com/syntafin/dc028e3d9a6863dcef5d26a0bbc9ea96

Last shown prompt is in Line 50-56, everything else doesnt appear (migration still completes on local).

Steps To Reproduce

  • Use Laravel Prompts
  • After 3 Prompts, everything else is skipped

Feature Request: Progress Bar

Amazing work, Jess. laravel/prompts is mint πŸ‘Œ

I would love to suggest a progress bar component.

It's not really an input, but it is something you could cancel, or it could be combined with a text input - for example entering a URL to download from.

For example:

  • Label
  • Cancelled state
  • Customise the display value for the numerator/denominator
  • Pending mode (like a loading spinner variant if progress is unknowable)
  • Parallel progress bars? - or maybe parallel output could be a seperate feature of its own
  • Maybe Http download support, i.e. sugar for Http::sink('/path/to/file')->withOptions(['progress' => ...])->get($url)

Add help text or expected input to multi-select prompts

When presented with a multi-select prompt, it's not clear what input is expected in order to select options:

Screenshot 2023-08-11 at 11 00 14 PM

I looked in the docs but didn't see any info there. Ultimately I ended up on the issue tracker where another user had the same issue: #41 I tried various key combinations (y/n, 1/0, return, tab/ctrl/shift/alt/cmd combinations) but spacebar wasn't one of them 🫣. A line that says "Use spacebar to select options" or a mention in the docs (or both) would definitely help here.

@jessarcher You mentioned the possibility of adding this feature #41 (comment) so I figured I'd open up an issue to +1 the idea.

Real Time Validation

Laravel Prompts Version

Latest

Laravel Version

prompt:text:default:required:validated

PHP Version

8.1.21

Operating System & Version

macOS 13.4.1

Terminal Application

iTerm2 3.4.19

Description

From what I could see, prompts have "real-time validation", but it only works after the first attempt to send some value. I don't know if it's bad behavior or if it was expected to happen. In any case, I am reporting to the care of the team. Demo: https://share.cleanshot.com/vddFkrXQLBZSxDjqh3s7

Steps To Reproduce

  1. Try to validate something
  2. The first validation will only work when you submit the value
  3. After that, all validation works like a "real time validation", when typing.

Artisan arrow keys don't work

Laravel Prompts Version

latest

Laravel Version

10.22.0

PHP Version

8.2.10

Operating System & Version

Windows 10

Terminal Application

PowerShell with SSH command

Description

The right and left keys do not work to select the option.
"^[[D" appears for the left key and "^[[C" for the right key, it is not possible to select the desired option.

WindowsTerminal_F2tZgpvOyn

Steps To Reproduce

  • on windows open powershell
  • ssh {user}@{domain.com}
  • php artisan migrate

Long options break `multisearch` options

Laravel Prompts Version

0.1.15

Laravel Version

N/A

PHP Version

8.1.23

Operating System & Version

MacOS

Terminal Application

iTerm2

Description

If one of the options passed to search() is longer than the size of the displayed box, the output looks broken, and using the up and down arrows makes the whole thing go haywire.

Partial output (EDIT - that doesn't show the problem as it doesn't wrap on here!)

 β”Œ Enter the Event names ───────────────────────────────────────────────────────────────────────────────────────────────────────────┐
 β”‚                                                                                                                                  β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 β”‚   β—» -- None --                                                                                                               ┃   β”‚
 β”‚   β—» \Drupal\block_content\BlockContentEvents::BLOCK_CONTENT_GET_DEPENDENCY - \Drupal\block_content\BlockContentEvents::BLOCK_… β”‚ β”‚
 β”‚   β—» \Drupal\user\Event\UserEvents::FLOOD_BLOCKED_USER - \Drupal\user\Event\UserEvents::FLOOD_BLOCKED_USER                    β”‚   β”‚
 β”‚   β—» \Drupal\user\Event\UserEvents::FLOOD_BLOCKED_IP - \Drupal\user\Event\UserEvents::FLOOD_BLOCKED_IP                        β”‚   β”‚

Steps To Reproduce

Supply an option which is longer than the width of the terminal.

Terminal Height and Width Exception

Laravel Prompts Version

0.1.3

Laravel Version

10.17.0

PHP Version

8.2

Operating System & Version

Linux

Terminal Application

Vs code terminal

Description

image


May be at this moment can we use old prompts which used in laravel 10.16!!?

Steps To Reproduce

#3

Can remove breaklines after text output

There are too newlines after text ouput. Is it possible to remove it?

CURRENT BEHAVIOR

php artisan some:prompt-command

output1

output2

output3

WANTED BEHAVIOR

php artisan some:prompt-command
output1
output2
output3

Discrepancy between `multiselect` return value and displayed value

Laravel Prompts Version

0.1.5

Laravel Version

10.19.0

PHP Version

8.2.8 (in docker image)

Operating System & Version

macOS 13.5 (Intel) + Docker 4.18.0 + Dockerimage mcr.microsoft.com/devcontainers/php:1-8.2-bullseye

Terminal Application

VSCode Terminal

Description

When using multiselect prompts with arrays matching the array_is_list requirement, the selected options are displayed differently as they are returned.

Steps To Reproduce

  1. Create a new command with the following code:
$selectedPermissions = multiselect(
    'Select permissions',
    [
        'create',
        'read',
        'write',
        'delete',
    ],
    [
        'read',
        'write',
    ]
);

dump($selectedPermissions);
  1. Select the default values (read + write)
  2. Observe the discrepancy between the displayed selected permissions and the actual selected permissions:
 β”Œ Select permissions ──────────────────────────────────────────┐
 β”‚ create                                                       β”‚
 β”‚ read                                                         β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

array:2 [ // app/Console/Commands/Bug.php:45
  0 => "read"
  1 => "write"
]

You can find a minimal example on a brand-new Laravel project here: https://github.com/irobin591/laravel-prompts-bug (see app/Console/Commands/Bug.php)

Any luck with more natural scroll list?

I yesterday tried to contribute to the project to support a natural scroll method, and I realized there is no view state variable. For detail:

  1. My expectation: Only when I scroll to an item outside of the displayed one, do I scroll to the displayed item on the page.
  2. Actual: When I scroll the list (select, multiselect, search), and options count is bigger than height, the highlighted option is always last one of view, related code:
    return $lines->slice($focused - $height + 1, $height);
  3. And I tried to add a variable to render, I realize renderer creates every input time. So I also added a static instance variable to persist this object, but another bug appeared: it will top up the previous window.
  4. As far as I know, the Prompt class is the only one that can be used as storing view state.

I would be happy if you could provide some ideas or if this issue could be resolved appropriately. I don't know if this is more reasonable.

STDIN complain

Laravel Prompts Version

v0.1.9

Laravel Version

10.25.0

PHP Version

8.2.10

Operating System & Version

Linux

Terminal Application

Linux

Description

Hi. After upgrading laravel from 10.24.0 to 10.25.0 witch has laravel/prompts v0.1.9, when i want to call a command from controller Artisan::call('app:set-version'); i get this error:

[2023-09-26 19:26:53] production.ERROR: Undefined constant "Illuminate\Console\Concerns\STDIN" {"userId":40009,"exception":"[object] (Error(code: 0): Undefined constant \"Illuminate\\Console\\Concerns\\STDIN\" at /home/crm/public_html/vendor/laravel/framework/src/Illuminate/Console/Concerns/ConfiguresPrompts.php:27)
....

Steps To Reproduce

Artisan::call('any-command')

SelectPrompt $required is not allowed to be false

Laravel Prompts Version

v0.1.12

Laravel Version

v10.29.0

PHP Version

8.2.11

Operating System & Version

Debian GNU/Linux 12 (bookworm) (php:8.2.11-fpm docker image)

Terminal Application

GNOME Terminal

Description

Hi Jess and Co. Prompts is a useful package and I appreciate the effort put in to it.

The relatively recent change f48bc94 forces SelectPrompt's $required bool|string to not be false anymore.

This broke the prompts for me because of the way I use the SelectPrompt.

In my project, I give the user a number of options to choose from. The last option is sometimes called "Back" and sometimes called "Quit", and has a key of '' (an empty string). For me an empty string is a consistent way of checking that the user wants to return from the current prompt / go back / exit / quit etc without having to worry about the wording. e.g.

$options = [
    'database' => 'Database Management',
    'deploy' => 'Deployment',
    '' => 'Quit',
];

$choice = select(
    label: "Main",
    options: $options,
    required: false, // <<<< This would allow '' (i.e. Quit) to be chosen
);

if ($choice === '') {
    break;
}

(My actual code is abstracted and the $options are passed in, so it's less hard-coded than this).

I can get around it by setting $required to '', but it seems odd to solve it that way.

The commit explicitly checks to make sure that $required is not false, so I thought I'd ask about the reason behind that? Or am I simply not using it as intended?

Steps To Reproduce

$options = [
    'database' => 'Database Management',
    'deploy' => 'Deployment',
    '' => 'Quit',
];

$choice = select(
    label: "Main",
    options: $options,
);

if ($choice === '') {
    break;
}

The Quit option can't be picked.

 β”Œ Main ────────────────────────────────────────────────────────┐
 β”‚   β—‹ Database Management                                      β”‚
 β”‚   β—‹ Deployment                                               β”‚
 β”‚ β€Ί ● Quit                                                     β”‚
 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  ⚠ Required.

The system cannot find the path specified

Laravel Prompts Version

0.1.0

Laravel Version

10.10

PHP Version

8.1

Operating System & Version

Windows 10 Enterprise

Terminal Application

bash Terminal

Description

I used text and search methods in my command class then when I run the command this error is raised The system cannot find the path specified, after that when I tried to open TextPrompt (for example) I found that the class not exists.

Steps To Reproduce

When I use any method of that package this error message The system cannot find the path specified is raised.

documentation link broken

Laravel Prompts Version

1

Laravel Version

10.4.1

PHP Version

8.2

Operating System & Version

macos 13

Terminal Application

iterm

Description

Currently documentation link provided is broken. it leads to 404 page. I tried to search for it but couldn't find right path or else i would have sent pull request.

Steps To Reproduce

go to https://github.com/laravel/prompts

in official documentation section link is provided https://laravel.com/docs/prompts

when you click the link it redirects to 404 page.

Feature request: section support

I would love to see some support on sections.

Symfony has implementation for that, but was never really used in Laravel.

What it does is creating a segment in which you can add or delete lines while also having other segments which can be edited independently from each other.

One of the ideas is to be able to clear out prompts when entered information, but we can do so many things with sections. We could do live updating of sections using Laravel Reverb ;-)

An example of what could be done:

section('foo', function(){
     // anything in here happens within the section
     info('hello');
     // .... creating progressbars, requesting information.
})->clear();
info('we are done');

Another example:

info('asking questions:', section: 'foo');
$bar = section('bar');

$name = text('your name?', section: 'bar');
$bar->clear();
$password = password('your password?', section: $bar);
$bar->replace(
  function(){
     // replaces the entire content. Imagine it does more output.
     info('Thanks!');
  }
)

info('done asking questions.', section: 'foo');

Long options break search options

If one of the options passed to search() is longer than the size of the displayed box, the output looks broken, and using the up and down arrows makes the whole thing go haywire.

No output in combination with callSilent

Laravel Prompts Version

0.1.1

Laravel Version

10.17.0

PHP Version

8.2.8

Operating System & Version

macOS 13.5

Terminal Application

iTerm

Description

Previous calls to $this->callSilent remove any output of the new prompts package.
Removing any $this->callSilent calls fixes the problem.

Even a simple example command as this:

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test-command';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
            $this->callSilent('about');
            confirm('Is this visible?');
    }
}

When running this command, no output is visible in the terminal but the application is waiting for user input.
Removing the $this->callSilent('about'); call fixes the issue.

Edit:

Manually calling Prompt::setOutput($this->output); also fixes the problem, like this:

$this->callSilent('about');
Prompt::setOutput($this->output);
confirm('Is this visible?');

So I suppose that the callSilent somehow resets Prompt's output interface.

Steps To Reproduce

I created a test repository here: https://github.com/mpociot/prompts-call-silent

To reproduce:

git clone https://github.com/mpociot/prompts-call-silent.git
cd prompts-call-silent
cp .env.example .env
php artisan key:generate
php artisan app:test-command

Multi-byte characters make the right border position incorrect

Laravel Prompts Version

v0.1.1 (I also tested dev-main)

Laravel Version

Independent installation of prompts

PHP Version

8.2.8

Operating System & Version

macOS 13.0

Terminal Application

Terminal

Description

When I input multi-byte characters (such as Chinese, Japanese, Emoji, etc.), the width of the border at the end changes. These multibyte characters occupy 2 spaces, but the calculation boundary may use its actual length (3 spaces).

Maybe using mb_strwidth to solve this?

Steps To Reproduce

image image

schedule:test does not print any output when running inside a php debian docker image

Laravel Prompts Version

0.1.9

Laravel Version

10.25.1

PHP Version

8.2.8

Operating System & Version

linux

Terminal Application

xterm-256color (echo $TERM)

Description

i am running my php image

on a linux debian console like this:

docker run --rm -it -v ${PWD}:/app  -w /app --init michabbb/php:8.2.bullseye php artisan schedule:test

and i donΒ΄t see any output. if I hit "enter" the first scheduled command will run. i looks like the cursor is working but
there is no output at all.

Steps To Reproduce

the dockerfile is very basic:

FROM php:8.2.8-fpm-bullseye

# Set non-interactive mode
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    libbz2-dev \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libgmp-dev \
    libmagickwand-dev \
    libicu-dev \
    libzip-dev \
    libxml2-dev \
    libxslt-dev \
    libonig-dev \
    libmemcached-dev \
    zlib1g-dev \
    libcurl4-openssl-dev \
    libssl-dev \
    libgearman-dev \
    libsqlite3-dev \
    git \
    unzip

# Configure and install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd

# Install Gearman extension from source
RUN curl -L -o /tmp/gearman.tar.gz https://github.com/php/pecl-networking-gearman/archive/8fb88d5a97111a7e8f0dc67553c387b49f047e53.tar.gz \
    && mkdir -p /tmp/gearman \
    && tar -xf /tmp/gearman.tar.gz -C /tmp/gearman --strip-components=1 \
    && rm /tmp/gearman.tar.gz \
    && ( \
        cd /tmp/gearman \
        && phpize \
        && ./configure \
        && make -j$(nproc) \
        && make install \
    ) \
    && rm -r /tmp/gearman 
#   && docker-php-ext-enable gearman

# Install PHP extensions
RUN docker-php-ext-install \
    bcmath \
    bz2 \
    calendar \
    gd \
    gmp \
    intl \
    mysqli \
    opcache \
    pcntl \
    pdo_mysql \
    soap \
    sockets \
    xsl \
    zip

# Install PECL extensions
RUN pecl install imagick \
    && pecl install memcached \
    && pecl install redis \
    && pecl install xdebug \
    && docker-php-ext-enable imagick redis

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

Porting interactive functionality to Symfony

I asked about this on Twitter last week, but I realize that is not the best place to discuss this. I'm really digging the interactive prompts (arrow-based choice lists & completion dropdowns) of this library! This is something I was trying to introduce to Symfony Console for many years (but lacking the stty skills needed for this).

Would it be an idea to see if this part of Prompts can be ported back to Symfony Console, a library you already depend on in the Laravel ecosystem and this library? That way, a larger part of the PHP ecosystem can have this much better terminal UX (including tooling used in the Laravel ecosystem like Composer and PHPstan).

The way I see it, this functionality is a perfect fit for the Question classes in Symfony Console. Laravel Prompts can then use the question classes, and add the custom "Laravel style" (plus any other extra integration, like the helper functions) on top of it.

Of course, given the code in this library is MIT, I can always try this proposal without your consent. But I'm looking forward to hear your ideas about this (e.g. did you try this and reached a major blocker already, is this just "not worth it" for your time, are you happy to try this out, or can I stalk a bit when experimenting with this myself 😁 )

Debounce with search()

I'm using search() to request data from an external API and it would be really cool to have some kind of debounce to not make a request on every keystroke.

Is there some smart way of doing this?

The Select Component is not responding to the arrow keys

Laravel Prompts Version

I couldn't find out the prompts version.

Laravel Version

10.17.1

PHP Version

8.2

Operating System & Version

macOS 13.5 (M1)

Terminal Application

iTerm

Description

After installing a fresh laravel and creating a new model, I was asked Would you like any of the following?. As far as I understand, I should be able to select the desired options with the arrow keys. Unfortunately the arrow keys do not work, it only works with H and J.

I am using iTerm 3.4.19 (tried also the native terminal)
Apple MacBook Pro M1 Pro

Steps To Reproduce

Screenshot 2023-08-02 at 19 10 21

Unable to select any options in a multi-select prompt on Windows WSL2

Laravel Prompts Version

0.1.3

Laravel Version

10.17.1

PHP Version

8.2.8

Operating System & Version

Windows 10 Pro - 22H2

Terminal Application

WSL2 (via VS Code / Windows Terminal)

Description

Hi, I'm unable to select any options with multi-select prompts.

This is my first experience using the new prompts package by running breeze:install on a new verison of Laravel. I want to enable options here (e.g. "Dark mode") but seem unable to do so. I can only submit it with none selected.

image

Windows WSL2, same issue both via VS Code terminal and also directly in Windows Terminal for Ubuntu.

laravel prompts 0.1.3

I have tried several different control and alphanumeric keys on my keyboard, to no effect. I can only navigate up and down between options, but not select them.

In another issue, @jessarcher mentioned this:

Could you try running the following minimal debugging script on the affected command line

This is my result with that script... entering: UP, DOWN, LEFT, RIGHT, h, j, ENTER, Ctrl+C:

"\u001b[A"
"\u001b[B"
"\u001b[D"
"\u001b[C"
"h"
"j"
"\n"
"\u0003"
Restoring TTY

How do I select an option from this list?

Steps To Reproduce

Use any artisan command that uses an optional multi-select list of options, e.g. php artisan breeze:install

Spinner runs `$callback()` twice if statically rendered

Laravel Prompts Version

0.1.6

Laravel Version

10.1.2

PHP Version

8.1.4

Operating System & Version

Ubuntu 20.04 via WSL

Terminal Application

Windows Terminal

Description

First time bug submitter for OSS, if I need to add any more detail let me know!

When using Spinner (not documented yet, found when viewing source) if rendered statically, it will run $callback() twice.

It appears in the Spinner.php class, in the spin() method it calls it here:

if (! function_exists('pcntl_fork')) {
    $this->renderStatically($callback);
}
protected function renderStatically(Closure $callback): mixed
    {
        $this->static = true;
        $this->render();
        return $callback();
    }

And then regardless if it ran via the renderStatically() method, it will run it again in the try block.

Steps To Reproduce

Create a spinner, and have it call statically. Add a echo to the function called, and it will write it to terminal twice if the spinner is rendered statically, only once if rendered normally.

Can't type "0" on a text input: Uninitialized string offset 0

Laravel Prompts Version

0.1.0

Laravel Version

10.16.1

PHP Version

8.2.6

Operating System & Version

Ubuntu (Laravel Homestead)

Terminal Application

Oh My Zsh

Description

When I prompt the user to enter a text, if the character "0" (zero) is present in the input the command fails immediately.

$userID = text(
label: "Type the user ID"
);
$this->info($userID);

Steps To Reproduce

Run the command and type "0" in the input field.

ErrorException

Uninitialized string offset 0

at vendor/laravel/prompts/src/Concerns/TypedValue.php:43
39β–• $this->cursorPosition = strlen($this->typedValue);
40β–• }
41β–•
42β–• $this->on('key', function ($key) use ($submit) {
➜ 43β–• if ($key[0] === "\e") {
44β–• match ($key) {
45β–• Key::LEFT => $this->cursorPosition = max(0, $this->cursorPosition - 1),
46β–• Key::RIGHT => $this->cursorPosition = min(strlen($this->typedValue), $this->cursorPosition + 1),
47β–• Key::DELETE => $this->typedValue = substr($this->typedValue, 0, $this->cursorPosition).substr($this->typedValue, $this->cursorPosition + 1),

  +5 vendor frames 

6 app/Console/Commands/Commit.php:30
Laravel\Prompts\text()

  +12 vendor frames 

19 artisan:35
Illuminate\Foundation\Console\Kernel::handle()

character "❯" cant show on windows

Laravel Prompts Version

0.1.11

Laravel Version

10.26.2

PHP Version

8.2

Operating System & Version

Windows

Terminal Application

cmder

Description

image
character "❯" cant show on windows, it show square with question mask

Steps To Reproduce

run function text:

dump(
    text('What is your name?', 'placeholder', 'SocolaDaiCa', true, function ($value) {
            if ($value === 'bad') {
                return 'a';
            }

            return '';
        }, 'hint'
    )
);

Press any key to continue?

I know this sounds a bit silly... But is there a way to ask the user to press any key to continue?
I don't need to prompt any choice between two values.
After reading a text or a warning, I would like him to press any key to continue.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.