summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs
index 45d2430..19e6e1b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,14 +23,12 @@ use crate::config::{
use crate::function::{eval_tool_calls, need_send_tool_results};
use crate::render::render_error;
use crate::repl::Repl;
-use crate::utils::{
- create_abort_signal, create_spinner, extract_block, get_env_name, run_command,
- run_with_spinner, AbortSignal, Shell, CODE_BLOCK_RE, IS_STDOUT_TERMINAL, SHELL,
-};
+use crate::utils::*;
use anyhow::{bail, Result};
use clap::Parser;
-use inquire::{Select, Text};
+use inquire::validator::Validation;
+use inquire::Text;
use is_terminal::IsTerminal;
use parking_lot::RwLock;
use simplelog::{format_description, ConfigBuilder, LevelFilter, SimpleLogger, WriteLogger};
@@ -241,28 +239,41 @@ async fn shell_execute(config: &GlobalConfig, shell: &Shell, mut input: Input) -
return Ok(());
}
if *IS_STDOUT_TERMINAL {
+ let options = ["execute", "revise", "describe", "cancel"];
+ 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
+ .iter()
+ .map(|v| format!("{}{}", color_text(&v[0..1], first_letter_color), &v[1..]))
+ .collect::<Vec<String>>()
+ .join(&dimmed_text(" | "));
loop {
- let answer = Select::new(
- eval_str.trim(),
- vec!["✅ Execute", "🔄 Revise", "📖 Explain", "❌ Cancel"],
- )
- .prompt()?;
+ 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(),
+ )),
+ })
+ .prompt()?;
- match answer {
- "✅ Execute" => {
+ match answer.as_str() {
+ "e" => {
debug!("{} {:?}", shell.cmd, &[&shell.arg, &eval_str]);
let code = run_command(&shell.cmd, &[&shell.arg, &eval_str], None)?;
if code != 0 {
process::exit(code);
}
}
- "🔄 Revise" => {
+ "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).await;
}
- "📖 Explain" => {
+ "d" => {
let role = config.read().retrieve_role(EXPLAIN_SHELL_ROLE)?;
let input = Input::from_str(config, &eval_str, Some(role));
let abort = create_abort_signal();