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 tab-autocompletion, clear line with ctrl+c, fix minor bug #65

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Satellile
Copy link

  • Pressing tab completes the rest of the command. Continuing to press tab cycles through other potential completions.
    e.g. typing he and pressing tab results in help. If there's another command called heat, pressing tab again could result in heat.
  • Via a new ConsoleConfiguration field, users can manually add autocompletion for command arguments.
    e.g. after setting up the config, you could type set_color tur and pressing tab results in set_color turquoise
  • Pressing Ctrl + C clears the current line
  • Fix the bug where an "L" is printed onto the console line when clearing the console history with Ctrl + L

The autocompletion code is functional but a bit verbose and messy. It annoyingly doesn't move the text cursor to the end of the line after autocompleting, I wasn't sure how to fix that, but it didn't bother me enough to try to figure it out.

I don't use github often so I'm unfamiliar with pull request etiquette, sorry if I put too many changes into a single pull request. I can try to make multiple pull requests for the individual changes if needed.

@makspll
Copy link
Collaborator

makspll commented Mar 27, 2024

Hi, thanks for the PR!

All looks good apart from the mechanism, could we not have some sort of trie lib like: https://docs.rs/trie-rs/latest/trie_rs/ power it?

For example we could just populate it with command names automatically and do a prefix search like:

'he' -> 'he*' -> 'help','hello'

Then pick the closest common prefix ('hel' here) auto complete to it, and display the rest of the results

@Satellile
Copy link
Author

trie_rs looks perfect for this! I just uploaded commits adding it in to replace what I wrote before.

Currently, when you press Tab, it uses trie_rs's prefix search to find matching commands/arguments and provide a completion. It stores all the matching completions in state.completions, so If you keep pressing tab, it will cycle through other possible completions (e.g. typing 'hel' and pressing tab repeatedly would cycle through 'help' and 'hello').

I think displaying all matching completions would be quite useful, but I'm a bit too unfamiliar with egui to want to implement a new ui node atm.

@eupraxia05 eupraxia05 mentioned this pull request Jun 23, 2024
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