From 51b719c85016cef188e63c07fce5706bf78e48c8 Mon Sep 17 00:00:00 2001 From: iff Date: Tue, 19 Nov 2024 15:15:47 +0100 Subject: [PATCH] style: better formating from AI --- src/suggestions.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/suggestions.rs b/src/suggestions.rs index d0c5ec9..211db5e 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -60,7 +60,22 @@ pub fn suggest_command(shell: &str, last_command: &str, error_msg: &str) -> Opti use crate::requests::ai_suggestion; let suggest = ai_suggestion(last_command, error_msg); if let Some(suggest) = suggest { - eprintln!("{}: {}\n", t!("ai-suggestion").bold().blue(), suggest.note); + let suggest_note = suggest.note.split_whitespace().collect::>(); + let mut note = String::new(); + let mut line = String::new(); + for word in suggest_note { + if line.len() + word.len() > 80 { + note.push_str(&line); + note.push('\n'); + line.clear(); + } + line.push_str(word); + line.push(' '); + } + note.push_str(&line); + + let warn = format!("{}:", t!("ai-suggestion")).bold().blue(); + eprintln!("{}\n{}\n", warn, note); let command = suggest.command; if command != "None" { if PRIVILEGE_LIST.contains(&split_command[0].as_str()) {