chromakitx 1.0.2

A comprehensive color manipulation library for Rust
Documentation
// SPDX-FileCopyrightText: 2023 CELESTIFYX Team
// SPDX-License-Identifier: GPL-3.0-or-later

use std::{
    fmt::{
        Display,
        Formatter,
        Result
    },

    ops::Add
};

use crate::ColorFormattable;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Color {
    formatted: String
}

impl Color {
    pub fn new(color: impl ColorFormattable, is_background: bool) -> Self {
        Self {
            formatted: color.format(is_background)
        }
    }

    pub fn formatted(&self) -> &str {
        &self.formatted
    }
}

impl Display for Color {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
        write!(f, "{}", self.formatted)
    }
}

impl Add<&str> for &Color {
    type Output = String;

    fn add(self, other: &str) -> String {
        format!("{}{}", self.formatted, other)
    }
}

impl Add<&Color> for &Color {
    type Output = String;

    fn add(self, other: &Color) -> String {
        format!("{}{}", self.formatted, other)
    }
}