why2-chat 2.1.4

Lightweight, fast and secure chat application powered by WHY2 encryption.
/*
This is part of WHY2
Copyright (C) 2022-2026 Václav Šmejkal

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

//CONSTS
pub const COLORS: [&str; 16] = //COLOR CODES
[
    "black",
    "dark_red",
    "dark_green",
    "dark_yellow",
    "dark_blue",
    "dark_magenta",
    "dark_cyan",
    "grey",
    "dark_grey",
    "red",
    "green",
    "yellow",
    "blue",
    "magenta",
    "cyan",
    "white",
];

pub const NONE: &str = "none"; //NO COLOR

//FUNCTIONS
pub fn name(code: Option<u8>) -> &'static str //COLOR TO CODE
{
    code.and_then(|code| COLORS.get(code as usize)).copied().unwrap_or(NONE)
}

pub fn code(name: &str) -> Option<u8> //CODE TO COLOR
{
    COLORS.iter().position(|color| color.eq_ignore_ascii_case(name)).map(|index| index as u8)
}