feat: add command template support for shell (#48)

This commit is contained in:
fzdwx 2023-08-12 23:57:35 +08:00 committed by GitHub
parent 1e3b17e58c
commit 0da93562c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 10 deletions

View File

@ -106,7 +106,11 @@ impl Executor {
}
"create" => cx.manager.create(),
"rename" => cx.manager.rename(),
"shell" => cx.manager.shell(exec.named.contains_key("block")),
"shell" => cx.manager.shell(
exec.args.get(0).map(|e| e.as_str()).unwrap_or(""),
exec.named.contains_key("block"),
exec.named.contains_key("confirm"),
),
"hidden" => cx.manager.current_mut().hidden(match exec.args.get(0).map(|s| s.as_str()) {
Some("show") => Some(true),
Some("hide") => Some(false),

View File

@ -62,7 +62,9 @@
- rename: Rename a file or directory.
- shell: Run a shell command.
- `exec`: Optional, command template to be run.
- `--block`: Block the UI until the command finishes.
- `--confirm`: When the template is provided, run it directly, no input UI was shown.
- hidden: Set the visibility of hidden files.

View File

@ -225,16 +225,21 @@ impl Manager {
pub fn bulk_rename(&self) -> bool { false }
pub fn shell(&self, block: bool) -> bool {
pub fn shell(&self, exec: &str, block: bool, confirm: bool) -> bool {
let mut exec = exec.to_owned();
tokio::spawn(async move {
let result = emit!(Input(InputOpt::top("Shell:").with_highlight()));
if let Ok(exec) = result.await {
emit!(Open(
Default::default(),
Some(Opener { exec, block, display_name: Default::default(), spread: true })
));
if !confirm || exec.is_empty() {
let result = emit!(Input(InputOpt::top("Shell:").with_value(&exec).with_highlight()));
match result.await {
Ok(e) => exec = e,
Err(_) => return,
}
}
emit!(Open(
Default::default(),
Some(Opener { exec, block, display_name: Default::default(), spread: true })
));
});
false

View File

@ -302,7 +302,7 @@ impl Scheduler {
})
});
let args = args.into_iter().map(|a| a.as_ref().to_os_string()).collect::<Vec<_>>();
let args = args.iter().map(|a| a.as_ref().to_os_string()).collect::<Vec<_>>();
tokio::spawn({
let process = self.process.clone();
let opener = opener.clone();