diff options
| author | sigoden <sigoden@gmail.com> | 2024-10-16 19:56:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-16 19:56:27 +0800 |
| commit | 98cc9879c7a87526548c325aa42eeb401cc11f35 (patch) | |
| tree | 36e7bfac05f0254a4b65b2d59cb244c8736f6bec /src/main.rs | |
| parent | 9935ecc12f9d84c4eb5c663f8d9362f6529d4ef2 (diff) | |
| download | aichat-98cc9879c7a87526548c325aa42eeb401cc11f35.tar.gz | |
feat: add shell action `copy` (#926)
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index b9bb54f..3725258 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,7 +245,7 @@ async fn shell_execute(config: &GlobalConfig, shell: &Shell, mut input: Input) - return Ok(()); } if *IS_STDOUT_TERMINAL { - let options = ["execute", "revise", "describe", "cancel"]; + let options = ["execute", "revise", "describe", "copy", "quit"]; let command = color_text(eval_str.trim(), nu_ansi_term::Color::Rgb(255, 165, 0)); let first_letter_color = nu_ansi_term::Color::Cyan; let prompt_text = options @@ -257,12 +257,14 @@ async fn shell_execute(config: &GlobalConfig, shell: &Shell, mut input: Input) - println!("{command}"); let answer = Text::new(&format!("{prompt_text}:")) .with_default("e") - .with_validator(|input: &str| match matches!(input, "e" | "r" | "d" | "c") { - true => Ok(Validation::Valid), - false => Ok(Validation::Invalid( - "Invalid option, choice one of e, r, d or c".into(), - )), - }) + .with_validator( + |input: &str| match matches!(input, "e" | "r" | "d" | "c" | "q") { + true => Ok(Validation::Valid), + false => Ok(Validation::Invalid( + "Invalid option, choice one of e, r, d, c or q".into(), + )), + }, + ) .prompt()?; match answer.as_str() { @@ -292,6 +294,10 @@ async fn shell_execute(config: &GlobalConfig, shell: &Shell, mut input: Input) - println!(); continue; } + "c" => { + set_text(&eval_str)?; + println!("{}", dimmed_text("✓ Copied the command")); + } _ => {} } break; |
