Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fileselector prompt #5

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

macocci7
Copy link
Contributor

@macocci7 macocci7 commented Jul 14, 2024

This PR adds support for file selector.

Here's a demo video, which you can play with for yourself using php playground/fileselector.php on this branch.

2024-05-29.00-13-46.mp4

Purpose

fileselector provides assistance in entering file paths quickly and accurately in interactive mode.

Usage

use function ArtisanBuild\CommunityPrompts\fileselector;

fileselector(
    label: 'Select a file to import.',
    placeholder: 'E.g. ./vendor/autoload.php',
    validate: fn (string $value) => match (true) {
        !is_readable($value) => 'Cannot read the file.',
        default => null,
    },
    hint: 'Input the file path.',
    extensions: [
        '.json',
        '.php',
    ],
);

This function lists the entries in the directory on the local file system that matches the input, as the options for suggest.

You can automatically complete the input like the suggest prompt by pressing TAB on the selected option, then continue to input.
Press Enter to finish input.
Actually this function was created from the copy of the suggest promt.

You can filter the options with the parameter extensions.
If the parameter extensions is specified, the path and directories whose path ends match one of the extensions array elements are returned as options.

@ProjektGopher
Copy link
Member

@macocci7 Thx for agreeing to contribute! Can you make a folder named Docs and start a document for this prompt in there? I'm going to have to start filling in some gaps for my own features, but I think it's best to start documenting early

@macocci7
Copy link
Contributor Author

I've added Docs folder and Docs/fileselector.md.
Is this what you want?

@ProjektGopher
Copy link
Member

That's exactly what I wanted, thx @macocci7! I'll try to make some time tomorrow to finalize this and merge it. I've got 2 or 3 more PRs of my own to finish off here this week, then I'll be tagging another version and then I'll make another announcement.

@ProjektGopher ProjektGopher merged commit 52a2d27 into artisan-build:main Jul 19, 2024
4 checks passed
@macocci7 macocci7 deleted the add_file_selector branch August 8, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants