From e63d55110ef49f721664450ae99cc9f0ec399770 Mon Sep 17 00:00:00 2001 From: iff Date: Sat, 12 Aug 2023 22:39:00 +0200 Subject: [PATCH] feat: redirect all output to stderr --- src/main.rs | 8 +++++--- src/suggestions.rs | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 876af1a..4ba1f85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,8 @@ mod style; mod suggestions; fn main() { + colored::control::set_override(true); + args::handle_args(); let shell = match std::env::var("_PR_SHELL") { @@ -59,7 +61,7 @@ fn main() { format!("{}", "Looking for new suggestion...".cyan().bold()); // println!("\n{} {}", "ERROR:".red().bold(), msg); - println!("\n{}\n", retry_message); + eprintln!("\n{}\n", retry_message); } } else { break; @@ -68,11 +70,11 @@ fn main() { break; } } - println!( + eprintln!( "No correction found for the command: {}\n", last_command.red() ); - println!( + eprintln!( "If you think there should be a correction, please open an issue or send a pull request!" ); } diff --git a/src/suggestions.rs b/src/suggestions.rs index 85c6655..c87f242 100644 --- a/src/suggestions.rs +++ b/src/suggestions.rs @@ -1,3 +1,5 @@ +use std::io::stderr; +use std::os::fd::AsFd; use std::process::{exit, Stdio}; use std::time::{Duration, Instant}; @@ -201,8 +203,8 @@ fn compare_string(a: &str, b: &str) -> usize { } pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Result<(), String> { - println!("{}\n", highlighted); - println!("Press enter to execute the suggestion. Or press Ctrl+C to exit."); + eprintln!("{}\n", highlighted); + eprintln!("Press enter to execute the suggestion. Or press Ctrl+C to exit."); std::io::stdin().read_line(&mut String::new()).unwrap(); for p in PRIVILEGE_LIST { @@ -215,7 +217,8 @@ pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Resu .arg(shell) .arg("-c") .arg(&command) - .stdout(Stdio::inherit()) + // .stdout(Stdio::inherit()) + .stdout(stderr().as_fd().try_clone_to_owned().unwrap()) .stderr(Stdio::inherit()) .spawn() .expect("failed to execute process") @@ -245,7 +248,8 @@ pub fn confirm_suggestion(shell: &str, command: &str, highlighted: &str) -> Resu let process = std::process::Command::new(shell) .arg("-c") .arg(command) - .stdout(Stdio::inherit()) + // .stdout(Stdio::inherit()) + .stdout(stderr().as_fd().try_clone_to_owned().unwrap()) .stderr(Stdio::inherit()) .spawn() .expect("failed to execute process")