feat: add interactive cd

This commit is contained in:
XYenon 2023-08-09 15:56:20 +08:00
parent d198f142e2
commit 598d63ccb9
3 changed files with 22 additions and 3 deletions

View file

@ -1,4 +1,4 @@
use core::{emit, files::FilesSort, input::InputMode};
use core::{files::FilesSort, input::InputMode};
use std::path::PathBuf;
use config::{keymap::{Control, Exec, Key, KeymapLayer}, manager::SortBy, KEYMAP};
@ -67,8 +67,8 @@ 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
let interactive = exec.named.contains_key("interactive");
cx.manager.active_mut().cd_interactive(interactive, path)
}
// 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

@ -74,6 +74,24 @@ impl Tab {
true
}
pub fn cd_interactive(&mut self, interactive: bool, target: PathBuf) -> bool {
if interactive {
tokio::spawn(async move {
let result = emit!(Input(InputOpt::top("Path:").with_value(target.to_string_lossy())));
if let Ok(path) = result.await {
let path = PathBuf::from(path);
emit!(Cd(path));
}
Ok::<(), Error>(())
});
}
else {
emit!(Cd(target));
}
false
}
pub async fn cd(&mut self, mut target: PathBuf) -> bool {
let file = if let Ok(f) = File::from(&target).await {
f