feat: add UX to cycle through completions in the REPL
Subtask of #1845
Description
What is the purpose of this pull request?
This pull request:
- replaces readline's built-in completer with a new UX that allows highlighting and navigating completions.
Related Issues
Does this pull request have any related issues?
This pull request:
- subtask of #1845
- updates #1855
Questions
Any questions for reviewers of this pull request?
No.
Other
Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.
Recording of new behavior:
https://github.com/stdlib-js/stdlib/assets/130062020/6ce1e4d8-076e-412b-9e2c-ad8f44c94877
Checklist
Please ensure the following tasks are completed before submitting this pull request.
- [x] Read, understood, and followed the contributing guidelines.
@stdlib-js/reviewers
@Planeshifter I updated the code, now one can only traverse what they see. And as we also support interactive terminal window sizes, they can always resize. Here's a video demonstrating this:
https://github.com/stdlib-js/stdlib/assets/130062020/6e8b4756-f7a4-4be4-b5cf-819ebd4dc2c4
@Snehil-Shah Pulled down the latest and played around. Works nicely. Thanks for working on this.
One comment: currently, when I enter co and then TAB, I get a list of potential matches. When I enter the next letter, such as n, the list of potential matches disappears and I need to hit TAB again to see the updated list. I then need to repeat this sequence for each new character until I've completed an identifier.
What I wonder is whether we should eliminate the need for repeatedly hitting TAB in order to see the list of potential matches. In terms of UX, one thing I do when seeing completion possibilities is use the list to help guide my spelling, having immediate feedback that I've misspelled something when the list disappears due to a spelling mistake.
In which case, I wonder if hitting TAB and triggering a completion list should trigger a "completion mode" in which the list of completions is continually displayed and updated as I enter new characters, without needing to explicitly hit TAB after every entered character.
Not sure how feasible this suggestion is.
@kgryte Done. It works from how much I've tried. Can you confirm if this is the behavior you were suggesting so I can write tests for this?
- Once you trigger the completions panel using TAB, you can only turn it off using TAB, ENTER, SIGINT events, or an up arrow when on the current line.
- normal typing including backspaces and arrow movements sustains and updates the completions panel.
- If you end up typing something with no completions to show, it doesn't automatically close the completer. Meaning you can go back and fix your spelling mistakes without needing to toggle the completer again
@Snehil-Shah Yes, this is what I was thinking. Thanks for the updates. The only other small niggle is that, when I type con and hit TAB, the completions display. When I continue typing const, the completions disappear due to an exact match with const; however, const may not be what I want, but I am no longer able to see the possibilities until I hit the next character consta. I wonder if it would make sense to keep the completion options still visible even when an exact match.
@kgryte The new UX doesn't make the completions disappear due to an exact match. Turns out it's a bug in the completer callback and not the completerEngine, and it is only specific to const. For example, typing conj while in tab completions view, correctly displays both conj and conjf.
I will investigate this and fix it in a separate patch PR.
Also, wrote the test for this and the specific case you mentioned of an exact match.