-
Notifications
You must be signed in to change notification settings - Fork 158
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
Conversation
pub fn commands() -> Vec<&'static str> { | ||
vec![$($cmd_value,)*] | ||
lazy_static! { | ||
pub static ref COMMANDS: Vec<&'static str> = vec![$($cmd_name,)*]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> = { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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,)*]; |
There was a problem hiding this comment.
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
As anticipated in #502, this is my implementation of a comprehensive autocompletion for each command (closes #180), which can be of 4 kinds:
cd
,new_tab
)shell
,spawn
)More details in the comments below.