diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs index 444340b..369a282 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,12 +26,10 @@ use crate::utils::*; use anyhow::{bail, Result}; use clap::Parser; -use inquire::validator::Validation; use inquire::Text; -use is_terminal::IsTerminal; use parking_lot::RwLock; use simplelog::{format_description, ConfigBuilder, LevelFilter, SimpleLogger, WriteLogger}; -use std::{env, io::stdin, process, sync::Arc}; +use std::{env, process, sync::Arc}; #[tokio::main] async fn main() -> Result<()> { @@ -262,9 +260,6 @@ async fn shell_execute( return Ok(()); } if *IS_STDOUT_TERMINAL { - if cfg!(target_os = "macos") && !stdin().is_terminal() { - bail!("Unable to read the pipe for shell execution on MacOS") - } 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; @@ -275,20 +270,11 @@ async fn shell_execute( .join(&dimmed_text(" | ")); loop { println!("{command}"); - let answer = Text::new(&format!("{prompt_text}:")) - .with_default("e") - .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()?; + let answer_char = + read_single_key(&['e', 'r', 'd', 'c', 'q'], 'e', &format!("{prompt_text}: "))?; - match answer.as_str() { - "e" => { + match answer_char { + 'e' => { debug!("{} {:?}", shell.cmd, &[&shell.arg, &eval_str]); let code = run_command(&shell.cmd, &[&shell.arg, &eval_str], None)?; if code == 0 && config.read().save_shell_history { @@ -296,13 +282,13 @@ async fn shell_execute( } process::exit(code); } - "r" => { + 'r' => { let revision = Text::new("Enter your revision:").prompt()?; let text = format!("{}\n{revision}", input.text()); input.set_text(text); return shell_execute(config, shell, input, abort_signal.clone()).await; } - "d" => { + 'd' => { let role = config.read().retrieve_role(EXPLAIN_SHELL_ROLE)?; let input = Input::from_str(config, &eval_str, Some(role)); if input.stream() { @@ -325,7 +311,7 @@ async fn shell_execute( println!(); continue; } - "c" => { + 'c' => { set_text(&eval_str)?; println!("{}", dimmed_text("✓ Copied the command.")); } |
