
#[derive(Clone)]
struct Chip8Keyboard {
    keys_state: [bool; 16]
}

impl Default for Chip8Keyboard {
    fn default() -> Self {
        Self { keys_state: [ 
            false, false, false, false,
            false, false, false, false,
            false, false, false, false,
            false, false, false, false
        ] }
    }
}

impl Chip8Keyboard {

    fn display_keyboard_key(self: Self, key_id: u8) {
        let filler = if self.is_pressed(key_id) { "*" } else { " " };
        print!("{}{}{}", filler, key_id, filler)
    }

    fn display_keyboard_horizontal_line(self: Self, row_values: [u8; 4]) {
        print!("|");
        for current in row_values {
            self.clone().display_keyboard_key(current);
            print!("|");
        }
        println!();
    } 

    fn display_keyboard_seperator_line(self: Self) {
        println!("+---+---+---+---+");

    }

    pub fn display_keyboard(self: Self) {
        self.clone().display_keyboard_seperator_line();
        self.clone().display_keyboard_horizontal_line(
            [1,2,3,0xC]
        );
        println!("+---+---+---+---+");
        println!("| 4 | 5 | 6 | D |");
        println!("+---+---+---+---+");
        println!("| 7 | 8 | 9 | E |");
        println!("+---+---+---+---+");
        println!("| A | 0 | B | F |");
        println!("+---+---+---+---+");
    }
    
    pub fn press_key(self: &mut Self, key_id: u8) {
        self.keys_state[key_id as usize] = true;
    }

    pub fn release_key(self: &mut Self, key_id: u8) {
        self.keys_state[key_id as usize] = false;
    }

    pub fn is_pressed(self: Self, key_id: u8) -> bool {
        self.keys_state[key_id as usize]
    }
}


#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn smoke_test() {
        assert_eq!(true, true);
    }
    
    #[test]
    fn basic_keyboard_display_works() {
        let basic_keyboard = Chip8Keyboard::default();

        
    }
}