Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
supplies auto complete function in interactive mode.Creating a file selector-like function is possible by using
suggest
prompt with callback foroptions
.However, automatically updating options after auto completion is impossible.
And filterling options with file
extensions
might be vervose.Using
fileselector
solves these issues and makes codes more simple.Usage
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 pressingTAB
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.Points to concern
FileSelector::autoComplete()
) Please let me know if there is a better way.SHIFT_TAB
key binding in order to useTAB
for input completion. Is there a problem?