zero-trust-rps 0.0.5

Online Multiplayer Rock Paper Scissors
Documentation
use ratatui::{
    style::{Color, Style},
    text::Span,
};

use crate::common::{
    hex::{parse_ascii_hex_digit, HEX_DIGITS},
    message::Hash,
};

const COLOUR_COUNT: usize = 16;
const FG_COLOURS: [Color; COLOUR_COUNT] = [
    Color::Blue,
    Color::Cyan,
    Color::Magenta,
    Color::Green,
    Color::Red,
    Color::Yellow,
    Color::LightBlue,
    Color::LightCyan,
    Color::LightMagenta,
    Color::LightGreen,
    Color::LightRed,
    Color::LightYellow,
    Color::DarkGray,
    Color::Gray,
    Color::Indexed(209), // Orange
    Color::Reset,
];

impl Hash {
    #[expect(clippy::needless_lifetimes)]
    pub fn get_span_iter<'a>(&'a self) -> impl Iterator<Item = Span<'static>> + 'a {
        match self {
            Hash::B3sum(owned_hex_str) => owned_hex_str
                .chars()
                .inspect(|ch| assert!(ch.is_ascii_hexdigit()))
                .zip(owned_hex_str.chars().rev())
                .map(move |(ch, other)| {
                    let value = parse_ascii_hex_digit(other).expect("needs to be ascii_hex_digit");
                    let fg = FG_COLOURS[value as usize];
                    Span::styled(
                        HEX_DIGITS[parse_ascii_hex_digit(ch).expect("needs to be ascii_hex_digit")
                            as usize],
                        Style::default().fg(fg),
                    )
                }),
        }
    }
}