// SPDX-FileCopyrightText: 2022-2024 Michael Picht <mipi@fsfe.org>
//
// SPDX-License-Identifier: GPL-3.0-or-later

//! # arch_msgs
//!
//! arch_msgs provides macros to print messages in the style that is used by
//! [Arch Linux](https://archlinux.org) scripts. Command line tools written in
//! Rust can print command line messages for errors, warnings, etc. with this
//! crate in the same style as Arch Linux scripts do.
//!
//! In an Arch Linux installation, corresponding functions are contained in the
//! script `/usr/share/makepkg/util/message.sh` and used by other scripts such
//! as `makepkg` or `mkarchroot`.
//!
//! ## Mapping of Arch Linux functions to the macros of this crate
//!
//! | Message type | Arch Linux function | Corresponding macro of this crate |
//! | :--- | :--- | :--- |
//! | Error | `error ...` | `error!(...)` |
//! | Information | `msg2 ...` | `info!(...)` |
//! | Message | `plain ...` | `msg!(...)` |
//! | Question | `ask ...` | `question!(...)` |
//! | Success | `msg ...` | `success!(...)` |
//! | Warning | `warning ...` | `warning!(...)` |
//!
//! All macros of this crate have the same signature as `println` and print a
//! new line at the end

pub use colored::Colorize;
extern crate colored;

/// Print an error message in Arch Linux style
#[macro_export]
macro_rules! error {
    ($($arg:tt)*) => {{
        eprintln!("{} {}","==> ERROR:".bold().bright_red(), format!($($arg)*).bold());
    }};
}

/// Print an information message in Arch Linux style
#[macro_export]
macro_rules! info {
    ($($arg:tt)*) => {{
        println!("{} {}","  ->".bold().bright_cyan(), format!($($arg)*).bold());
    }};
}

/// Print a message in Arch Linux style
#[macro_export]
macro_rules! msg {
    ($($arg:tt)*) => {{
        println!("{} {}","==>".bold().bright_green(), format!($($arg)*).bold());
    }};
}

/// Print a plain message in Arch Linux style
#[macro_export]
macro_rules! plain {
    ($($arg:tt)*) => {{
        println!("    {}".bold(), format!($($arg)*).bold());
    }};
}

/// Print a question in Arch Linux style
#[macro_export]
macro_rules! question {
    ($($arg:tt)*) => {{
        println!("{} {}","::".bold().bright_cyan(), format!($($arg)*).bold());
    }};
}

/// Print a warning in Arch Linux style
#[macro_export]
macro_rules! warning {
    ($($arg:tt)*) => {{
        println!("{} {}","==> WARNING:".bold().bright_yellow(), format!($($arg)*).bold());
    }};
}
