feat: add interactive cd (#43)

This commit is contained in:
XYenon 2023-08-09 22:30:02 +08:00 committed by GitHub
parent 866ed17044
commit 4823c0abc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -67,8 +67,12 @@ impl Executor {
"forward" => cx.manager.active_mut().forward(),
"cd" => {
let path = exec.args.get(0).map(PathBuf::from).unwrap_or_default();
emit!(Cd(path));
false
if exec.named.contains_key("interactive") {
cx.manager.active_mut().cd_interactive(path)
} else {
emit!(Cd(path));
false
}
}
// Selection

View File

@ -97,6 +97,7 @@ keymap = [
{ on = [ "g", "c" ], exec = "cd ~/.config" },
{ on = [ "g", "d" ], exec = "cd ~/Downloads" },
{ on = [ "g", "t" ], exec = "cd /tmp" },
{ on = [ "g", "<Space>" ], exec = "cd --interactive" },
]
[tasks]

View File

@ -115,6 +115,18 @@ impl Tab {
true
}
pub fn cd_interactive(&mut self, target: PathBuf) -> bool {
tokio::spawn(async move {
let result =
emit!(Input(InputOpt::top("Change directory:").with_value(target.to_string_lossy())));
if let Ok(target) = result.await {
emit!(Cd(PathBuf::from(target)));
}
});
false
}
pub fn enter(&mut self) -> bool {
let hovered = if let Some(ref h) = self.current.hovered {
h.clone()