use is_terminal::IsTerminal;
use std::io::{self, Write};
pub fn show_cancel_hint(show: bool) {
if !show {
return;
}
if !std::io::stderr().is_terminal() {
return;
}
let _ = writeln!(io::stderr(), "ℹ️ Press Ctrl+C to cancel this operation");
}
#[allow(dead_code)] pub fn show_cancelling_message() {
let _ = writeln!(io::stderr(), "\nCancelling operation...");
let _ = io::stderr().flush();
}
pub fn should_show_hint(file_size: u64) -> bool {
file_size > 1024 * 1024 }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_show_hint_for_large_files() {
assert!(should_show_hint(2 * 1024 * 1024)); assert!(should_show_hint(10 * 1024 * 1024)); }
#[test]
fn test_should_not_show_hint_for_small_files() {
assert!(!should_show_hint(512 * 1024)); assert!(!should_show_hint(1024 * 1024)); assert!(!should_show_hint(100)); }
#[test]
fn test_show_cancel_hint_does_not_panic() {
show_cancel_hint(true);
show_cancel_hint(false);
}
#[test]
fn test_show_cancelling_message_does_not_panic() {
show_cancelling_message();
}
}