-
Notifications
You must be signed in to change notification settings - Fork 395
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
feat: auto-completion for input component #324
Conversation
Thank you very much for your PR; this is a feature I've been wanting to implement for a while. 🙏🏻 Can we implement it asynchronously? This would allow us to move away from |
That's a good point. But I think we need to discuss how we can achieve asynchronization. Currently in my implementation, I define two callback functions: pub init_completion: Option<Box<dyn Fn(&str) -> Vec<String> + Send>>,
pub finish_completion: Option<Box<dyn Fn(&str, &str) -> String + Send>>, The As for this interface, if we finally refactor the whole codebase with async, it would be easy to change the two callbacks to the async version, as long as this hasn't been exposed as an extension API. But I'd be glad to hear if you have different opinions. |
I don't think there are any other cases where we need completion. In fact, I don't add the completion component directly into The reason why I want a dedicated component is I want to customize it's size more flexibly during the rendering (e.g. initially the input has a width of 50, but the completion part takes too many space that it requires a width of 100, or even needs to be changed for the next completion. In this case I don't think it's good to adjust the width of the input). I hope to hear if you have some advice on this. The completion looks like a semi-component to me, which is deeply coupling with the input but needs special rendering considerations. |
Sorry for the late response; these few days have been unexpectedly busy lol I revisited the code, and it appears that time-consuming tasks only occur in yazi/yazi-core/src/tab/commands/find.rs Lines 40 to 47 in 396f60d
|
@sxyazi I have made a new commit with support for async |
Thank you, I'll make the remaining done |
@XOR-op I think I have completed the implementation. Would you like to give it a review? |
It looks like the quit logic has some bugs. For example, when there has been a completion, push ESC twice will close the input component but leave the completion component open. |
ah sorry, I forgot to push the final piece of code... I just committed it 🤣 |
LGTM, the improved version is great! |
3.mp4
This PR implements auto-completion for input component. Specifically, a 2D table is used for the completion as what shells (e.g. zsh, fish) do. Currently, the only implemented completion functionality is interactive-cd, but other completion can benefit with this new component.