ramadhan-cli-rust 0.1.0

Ramadan-first CLI for Sehar and Iftar timings in your terminal
Documentation
pub const MOON_EMOJI: &str = "🌙";

const RAMADAN_GREEN_RGB: &str = "\u{1b}[38;2;128;240;151m";
const ANSI_GREEN: &str = "\u{1b}[32m";
const ANSI_RESET: &str = "\u{1b}[0m";

fn is_color_supported() -> bool {
    use std::io::IsTerminal;

    if std::env::var_os("NO_COLOR").is_some() {
        return false;
    }

    let term = std::env::var("TERM")
        .unwrap_or_default()
        .to_ascii_lowercase();
    if term == "dumb" {
        return false;
    }

    std::io::stdout().is_terminal()
}

fn supports_true_color() -> bool {
    let color_term = std::env::var("COLORTERM")
        .unwrap_or_default()
        .to_lowercase();
    color_term.contains("truecolor") || color_term.contains("24bit")
}

pub fn ramadan_green(value: &str) -> String {
    if !is_color_supported() {
        return value.to_string();
    }

    if !supports_true_color() {
        return format!("{ANSI_GREEN}{value}{ANSI_RESET}");
    }

    format!("{RAMADAN_GREEN_RGB}{value}{ANSI_RESET}")
}