From 8623ef0ee74ff48a5ee24ee032f5b549f662f09d Mon Sep 17 00:00:00 2001 From: UMTS at Teleco Date: Sun, 8 Mar 2026 07:30:34 +0100 Subject: goofy ah --- src/output.rs | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 src/output.rs (limited to 'src/output.rs') diff --git a/src/output.rs b/src/output.rs new file mode 100644 index 0000000..fe3b141 --- /dev/null +++ b/src/output.rs @@ -0,0 +1,209 @@ +use crate::types::{DomainResult, DomainStatus, ErrorKind}; +use colored::*; +use std::io::Write; +use std::path::PathBuf; + +pub fn print_available_table(results: &[DomainResult], no_color: bool, no_unicode: bool) { + let available: Vec<&DomainResult> = results.iter().filter(|r| r.is_available()).collect(); + + if available.is_empty() { + println!("No available domains found."); + return; + } + + let max_len = available.iter().map(|r| r.full.len()).max().unwrap_or(20); + let width = max_len + 4; // padding + + let title = "Available Domains"; + let title_padded = format!("{:^width$}", title, width = width); + + if no_unicode { + // ASCII box + let border = format!("+{}+", "-".repeat(width)); + println!("{}", border); + if no_color { + println!("|{}|", title_padded); + } else { + println!("|{}|", title_padded.green()); + } + println!("+{}+", "-".repeat(width)); + for r in &available { + println!("| {: ColoredString { + match status { + DomainStatus::Available => domain.green(), + DomainStatus::Registered { .. } => domain.red(), + DomainStatus::Error { kind, .. } => match kind { + ErrorKind::InvalidTld => domain.yellow(), + _ => domain.blue(), + }, + } +} + +pub fn print_csv(results: &[DomainResult]) { + println!("Domains, Status, Note"); + for r in results { + println!("{}, {}, {}", r.full, r.status_str(), r.note_str()); + } +} + +pub fn write_csv_file(results: &[DomainResult], path: &PathBuf) -> Result<(), String> { + let mut file = std::fs::File::create(path) + .map_err(|e| format!("Could not create CSV file: {}", e))?; + writeln!(file, "Domains, Status, Note") + .map_err(|e| format!("Write error: {}", e))?; + for r in results { + writeln!(file, "{}, {}, {}", r.full, r.status_str(), r.note_str()) + .map_err(|e| format!("Write error: {}", e))?; + } + Ok(()) +} + +pub fn print_errors(results: &[DomainResult], verbose: bool) { + for r in results { + if let DomainStatus::Error { kind, message } = &r.status { + match kind { + ErrorKind::InvalidTld => { + eprintln!("Error for {}, tld does not seem to exist", r.full); + } + _ => { + if verbose { + eprintln!("Error for {}, {} (raw: {})", r.full, message, message); + } else { + eprintln!( + "Error for {}, unknown error (enable verbose to see raw error)", + r.full + ); + } + } + } + } + } +} + +pub fn print_progress(current: usize, total: usize) { + let percent = (current as f64 / total as f64 * 100.0) as u32; + eprint!("\rParsing results : {}%", percent); + if current == total { + eprintln!("\rParsing results : Done "); + } +} -- cgit v1.2.3-70-g09d2