diff --git a/src/commands.rs b/src/commands.rs index 7550bae4c..0e2dfe513 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -25,7 +25,7 @@ use crate::{ self, concatenate_list_of_os_str, dir_is_empty, nice_directory_display, to_utf, try_infer, user_wants_to_continue_decompressing, }, - Opts, QuestionPolicy, Subcommand, + warning, Opts, QuestionPolicy, Subcommand, }; // Used in BufReader and BufWriter to perform less syscalls @@ -508,7 +508,11 @@ fn check_mime_type( // Try to detect the extension and warn the user if it differs from the written one let outer_ext = format.iter().next().unwrap(); if outer_ext != &detected_format { - info!("The file extension: `{}` differ from the detected extension: `{}`", outer_ext, detected_format); + warning!( + "The file extension: `{}` differ from the detected extension: `{}`", + outer_ext, + detected_format + ); if !user_wants_to_continue_decompressing(path, question_policy)? { return Ok(ControlFlow::Break(())); } diff --git a/src/macros.rs b/src/macros.rs index 1057120ab..349d7eaae 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -15,3 +15,19 @@ pub fn _info_helper() { print!("{}[INFO]{} ", *YELLOW, *RESET); } + +/// Macro that prints [WARNING] messages, wraps [`println`]. +#[macro_export] +macro_rules! warning { + ($($arg:tt)*) => { + $crate::macros::_warning_helper(); + println!($($arg)*); + }; +} + +/// Helper to display "[INFO]", colored yellow +pub fn _warning_helper() { + use crate::utils::colors::{ORANGE, RESET}; + + print!("{}[WARNING]{} ", *ORANGE, *RESET); +} diff --git a/src/utils/fs.rs b/src/utils/fs.rs index f8e87729c..11332a98f 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -81,6 +81,7 @@ pub fn nice_directory_display(os_str: impl AsRef) -> Cow<'static, str> { } /// Try to detect the file extension by looking for known magic strings +/// Source: https://en.wikipedia.org/wiki/List_of_file_signatures pub fn try_infer(path: &Path) -> Option { fn is_zip(buf: &[u8]) -> bool { buf.len() > 3 @@ -124,8 +125,8 @@ pub fn try_infer(path: &Path) -> Option { let buf = { let mut b = [0; 270]; - // Reading errors will just make the inferring fail - let _rn = std::fs::File::open(&path).map(|mut f| std::io::Read::read(&mut f, &mut b)); + // Reading errors will just make the inferring fail so its safe to ignore + let _ = std::fs::File::open(&path).map(|mut f| std::io::Read::read(&mut f, &mut b)); b }; @@ -179,6 +180,8 @@ pub mod colors { color!(RED = "\u{1b}[38;5;9m"); color!(WHITE = "\u{1b}[38;5;15m"); color!(YELLOW = "\u{1b}[38;5;11m"); + // Requires true color support + color!(ORANGE = "\u{1b}[38;2;255;165;0m"); color!(STYLE_BOLD = "\u{1b}[1m"); color!(STYLE_RESET = "\u{1b}[0m"); color!(ALL_RESET = "\u{1b}[0;39m");