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

feat: comprehensive autocompletion for each command #526

Merged
merged 1 commit into from
May 19, 2024

Conversation

Akmadan23
Copy link
Contributor

As anticipated in #502, this is my implementation of a comprehensive autocompletion for each command (closes #180), which can be of 4 kinds:

  • Any file
  • Directories (cd, new_tab)
  • Executable files (shell, spawn)
  • A custom list of arguments or flags

More details in the comments below.

pub fn commands() -> Vec<&'static str> {
vec![$($cmd_value,)*]
lazy_static! {
pub static ref COMMANDS: Vec<&'static str> = vec![$($cmd_name,)*];
Copy link
Contributor Author

@Akmadan23 Akmadan23 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a necessary change, but this way the vector is created just once instead of on each call.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I didn't know you could do that haha

}

impl Completion for Command {
fn completion_kind(cmd: &str) -> Option<CompletionKind> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially tried to match on self, but some commands need specific conditions to be successfully built via from_str, so matching just on the keyword seems to be the only solution. So this could have been a standalone function in ui/view/tui_textfield.rs, but I think that having it here as a trait of Command makes it more discoverable for future contributors.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks great 👍

use crate::ui::views::TuiView;
use crate::ui::widgets::{TuiMenu, TuiMultilineText};
use crate::ui::AppBackend;

lazy_static! {
static ref EXECUTABLES: Vec<&'static str> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generates the list of binaries in $PATH. Should work well both on unix and windows (I tested it on linux, can't confirm about windows).

}

impl Completion for Command {
fn completion_kind(cmd: &str) -> Option<CompletionKind> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks great 👍

pub fn commands() -> Vec<&'static str> {
vec![$($cmd_value,)*]
lazy_static! {
pub static ref COMMANDS: Vec<&'static str> = vec![$($cmd_name,)*];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I didn't know you could do that haha

@kamiyaa kamiyaa merged commit d799b49 into kamiyaa:main May 19, 2024
4 checks passed
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.

Better support for autocompletion
2 participants