summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs20
-rw-r--r--src/repl/mod.rs2
-rw-r--r--src/utils/clipboard.rs4
3 files changed, 16 insertions, 10 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;
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 9a70ba5..d1068fd 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -588,7 +588,7 @@ Type ".help" for additional help.
fn copy(&self, text: &str) -> Result<()> {
if text.is_empty() {
- bail!("Empty text")
+ bail!("No text to copy")
}
set_text(text)?;
Ok(())
diff --git a/src/utils/clipboard.rs b/src/utils/clipboard.rs
index c96057f..6617fa4 100644
--- a/src/utils/clipboard.rs
+++ b/src/utils/clipboard.rs
@@ -9,12 +9,12 @@ pub fn set_text(text: &str) -> anyhow::Result<()> {
let mut clipboard = CLIPBOARD.lock().unwrap();
match clipboard.as_mut() {
Some(clipboard) => clipboard.set_text(text)?,
- None => anyhow::bail!("No available clipboard"),
+ None => anyhow::bail!("Failed to copy the text; no available clipboard"),
}
Ok(())
}
#[cfg(any(target_os = "android", target_os = "emscripten"))]
pub fn set_text(_text: &str) -> anyhow::Result<()> {
- anyhow::bail!("No available clipboard")
+ anyhow::bail!("Failed to copy the text; no available clipboard")
}