use colored::{ColoredString, Colorize}; use std::process; use super::conf::VERSION; pub fn fatal(msg: &str) -> ! { println!("{}: {msg}", "fatal".red().bold()); process::exit(-1); } pub fn fmtcode(code: u16) -> ColoredString { match code { 200..=299 => code.to_string().green(), 300..=399 => code.to_string().yellow(), 400..=499 => code.to_string().bright_red(), 500..=599 => code.to_string().red().bold(), _ => code.to_string().black(), } } pub fn parsetitle(s: String) -> String { let mut out = String::with_capacity(s.len()); s.split_whitespace().for_each(|w| { if !out.is_empty() { out.push(' '); } out.push_str(w); }); out } pub fn parsehit(sc: u16, url: String, title: String) -> String { format!( "{} {} {} {}{}{}", fmtcode(sc), "|".black().bold(), url.white().underline(), "[".black().bold(), parsetitle(title).bright_cyan().bold(), "]".black().bold() ) } pub fn banner() { eprintln!( "{}{} {}", "speed".bright_cyan().bold(), "boat".bright_magenta().bold(), VERSION.black() ); }