aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.rs')
-rw-r--r--src/ui.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 2ec0821..38546ab 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -104,14 +104,13 @@ pub fn tool_line(name: &str, args: &serde_json::Value) {
104 let _ = std::io::stdout().flush(); 104 let _ = std::io::stdout().flush();
105} 105}
106 106
107pub fn tool_result(result: &Result<String, String>) { 107pub fn tool_result(summary: &str, aborted: bool) {
108 let text = match result { 108 let text = if aborted {
109 Ok(output) => output, 109 "aborted".to_string()
110 Err(error) => error, 110 } else {
111 crate::provider::truncate(summary.trim(), 100)
111 }; 112 };
112 let first = text.lines().find(|l| !l.trim().is_empty()).unwrap_or(""); 113 println!(" {} {}", paint("2", "└"), paint("2", &text));
113 let summary = crate::provider::truncate(first.trim(), 100);
114 println!(" {} {}", paint("2", "└"), paint("2", &summary));
115 let _ = std::io::stdout().flush(); 114 let _ = std::io::stdout().flush();
116} 115}
117 116
@@ -163,7 +162,7 @@ impl Approver {
163 self.yolo 162 self.yolo
164 } 163 }
165 164
166 fn ask(&self, question: &str) -> Answer { 165 fn ask(&self, question: &str, allow_always: bool) -> Answer {
167 if self.yolo { 166 if self.yolo {
168 return Answer::Yes; 167 return Answer::Yes;
169 } 168 }
@@ -174,7 +173,8 @@ impl Approver {
174 ); 173 );
175 return Answer::No; 174 return Answer::No;
176 } 175 }
177 print!("\n{} {} ", question, paint("2", "[y/N/a]")); 176 let hint = if allow_always { "[y/N/a]" } else { "[y/N]" };
177 print!("\n{} {} ", question, paint("2", hint));
178 let _ = std::io::stdout().flush(); 178 let _ = std::io::stdout().flush();
179 179
180 let mut line = String::new(); 180 let mut line = String::new();
@@ -183,7 +183,7 @@ impl Approver {
183 } 183 }
184 match line.trim().to_ascii_lowercase().as_str() { 184 match line.trim().to_ascii_lowercase().as_str() {
185 "y" | "yes" => Answer::Yes, 185 "y" | "yes" => Answer::Yes,
186 "a" | "always" => Answer::Always, 186 "a" | "always" if allow_always => Answer::Always,
187 _ => Answer::No, 187 _ => Answer::No,
188 } 188 }
189 } 189 }
@@ -194,7 +194,7 @@ impl Approver {
194 return true; 194 return true;
195 } 195 }
196 println!("{preview}"); 196 println!("{preview}");
197 match self.ask(&format!("apply this change to {path}?")) { 197 match self.ask(&format!("apply this change to {path}?"), true) {
198 Answer::Yes => true, 198 Answer::Yes => true,
199 Answer::Always => { 199 Answer::Always => {
200 self.edits_allowed = true; 200 self.edits_allowed = true;
@@ -209,6 +209,8 @@ impl Approver {
209 if self.yolo { 209 if self.yolo {
210 return true; 210 return true;
211 } 211 }
212 self.ask(&format!("run: {}", crate::provider::truncate(cmd, 200))) == Answer::Yes 212 // Bash prompts every call by design, so "always" is not offered here.
213 self.ask(&format!("run: {}", crate::provider::truncate(cmd, 200)), false)
214 == Answer::Yes
213 } 215 }
214} 216}