fn apply_event(&mut self, evt: &mut EventCore) {
        match evt.1 {
            // limitations: only two buttons may be held at once
            EventData::Mouse(ref mut m) => match &mut self.mouse {
                Some(state) => {
                    let mut buttons = state.0.buttons;
                    state.0 = m.clone();
                    match evt.0 {
                        // this code only runs when there are no buttons down
                        "mouseup" => {
                            buttons = 0;
                            state.1 = Vec::new();
                        }
                        "mousedown" => {
                            if state.1.contains(&m.buttons) {
                                // if we already pressed a button and there is another button released the button crossterm sends is the button remaining
                                if state.1.len() > 1 {
                                    evt.0 = "mouseup";
                                    state.1 = vec![m.buttons];
                                }
                                // otherwise some other button was pressed. In testing it was consistantly this mapping
                                else {
                                    match m.buttons {
                                        0x01 => state.1.push(0x02),
                                        0x02 => state.1.push(0x01),
                                        0x04 => state.1.push(0x01),
                                        _ => (),
                                    }
                                }
                            } else {
                                state.1.push(m.buttons);
                            }

                            buttons = state.1.iter().copied().reduce(|a, b| a | b).unwrap();
                        }
                        _ => (),
                    }
                    state.0.buttons = buttons;
                    m.buttons = buttons;
                }
                None => {
                    self.mouse = Some((
                        m.clone(),
                        if m.buttons == 0 {
                            Vec::new()
                        } else {
                            vec![m.buttons]
                        },
                    ));
                }
            },
            EventData::Wheel(ref w) => self.wheel = Some(w.clone()),
            EventData::Screen(ref s) => self.screen = Some(*s),
            EventData::Keyboard(ref mut k) => {
                let repeat = self
                    .last_key_pressed
                    .as_ref()
                    .filter(|k2| k2.0.key == k.key && k2.1.elapsed() < MAX_REPEAT_TIME)
                    .is_some();
                k.repeat = repeat;
                let new = k.clone();
                self.last_key_pressed = Some((new, Instant::now()));
            }
        }
    }
// stores current input state and transforms events based on that state
stores current input state and transforms events based on that state
stores current input state and transforms events based on that state
fn apply_event(&mut self, evt: &mut EventCore) {
        match evt.1 {
            // limitations: only two buttons may be held at once
            EventData::Mouse(ref mut m) => match &mut self.mouse {
                Some(state) => {
                    let mut buttons = state.0.buttons;
                    state.0 = m.clone();
                    match evt.0 {
                        // this code only runs when there are no buttons down
                        "mouseup" => {
                            buttons = 0;
                            state.1 = Vec::new();
                        }
                        "mousedown" => {
                            if state.1.contains(&m.buttons) {
                                // if we already pressed a button and there is another button released the button crossterm sends is the button remaining
                                if state.1.len() > 1 {
                                    evt.0 = "mouseup";
                                    state.1 = vec![m.buttons];
                                }
                                // otherwise some other button was pressed. In testing it was consistantly this mapping
                                else {
                                    match m.buttons {
                                        0x01 => state.1.push(0x02),
                                        0x02 => state.1.push(0x01),
                                        0x04 => state.1.push(0x01),
                                        _ => (),
                                    }
                                }
                            } else {
                                state.1.push(m.buttons);
                            }
                            buttons = state.1.iter().copied().reduce(|a, b| a | b).unwrap();
                        }
                        _ => (),
                    }
                    state.0.buttons = buttons;
                    m.buttons = buttons;
                }
                None => {
                    self.mouse = Some((
                        m.clone(),
                        if m.buttons == 0 {
                            Vec::new()
                        } else {
                            vec![m.buttons]
                        },
                    ));
                }
            },
            EventData::Wheel(ref w) => self.wheel = Some(w.clone()),
            EventData::Screen(ref s) => self.screen = Some(*s),
            EventData::Keyboard(ref mut k) => {
                let repeat = self
                    .last_key_pressed
                    .as_ref()
                    .filter(|k2| k2.0.key == k.key && k2.1.elapsed() < MAX_REPEAT_TIME)
                    .is_some();
                k.repeat = repeat;
                let new = k.clone();
                self.last_key_pressed = Some((new, Instant::now()));
            }
        }
    }
fn apply_event ( & mut self , evt : & mut EventCore ) { match evt . 1 { // limitations: only two buttons may be held at once EventData :: Mouse ( ref mut m ) => match & mut self . mouse { Some ( state ) => { let mut buttons = state . 0 . buttons ; state . 0 = m . clone ( ) ; match evt . 0 { // this code only runs when there are no buttons down " " => { buttons = 0 ; state . 1 = Vec :: new ( ) ; } " " => { if state . 1 . contains ( & m . buttons ) { // if we already pressed a button and there is another button released the button crossterm sends is the button remaining if state . 1 . len ( ) > 1 { evt . 0 = " " ; state . 1 = vec ! [ m buttons ] ; } // otherwise some other button was pressed. In testing it was consistantly this mapping else { match m . buttons { 0x01 => state . 1 . push ( 0x02 ) , 0x02 => state . 1 . push ( 0x01 ) , 0x04 => state . 1 . push ( 0x01 ) , _ => ( ) , } } } else { state . 1 . push ( m . buttons ) ; } buttons = state . 1 . iter ( ) . copied ( ) . reduce ( | a , b | a | b ) . unwrap ( ) ; } _ => ( ) , } state . 0 . buttons = buttons ; m . buttons = buttons ; } None => { self . mouse = Some ( ( m . clone ( ) , if m . buttons == 0 { Vec :: new ( ) } else { vec ! [ m buttons ] } , ) ) ; } } , EventData :: Wheel ( ref w ) => self . wheel = Some ( w . clone ( ) ) , EventData :: Screen ( ref s ) => self . screen = Some ( * s ) , EventData :: Keyboard ( ref mut k ) => { let repeat = self . last_key_pressed . as_ref ( ) . filter ( | k2 | k2 . 0 . key == k . key && k2 . 1 . elapsed ( ) < MAX_REPEAT_TIME ) . is_some ( ) ; k . repeat = repeat ; let new = k . clone ( ) ; self . last_key_pressed = Some ( ( new , Instant :: now ( ) ) ) ; } } }
stores current input state and transforms events based on that state
stores current input state and transforms events based on that state
&mut self
evt
&mut EventCore