pub fn on_scroll_event(&mut self, direction: Direction) -> usize {
        let now = Instant::now();
        let last_event = self.last_event.replace(now);
        let last_direction = self.last_direction.replace(direction);

        let has_direction_changed = last_direction.is_some_and(|last| last != direction);
        let is_scrolling_quickly =
            last_event.is_some_and(|last| now.duration_since(last) < DECAY_TIME);
        let is_throttling = last_event.is_some_and(|last| now.duration_since(last) < THROTTLE_TIME);

        if is_throttling {
            self.throttle_counter = (self.throttle_counter + 1) % THROTTLE_FACTOR;
            let should_throttle = self.throttle_counter != 0;
            if should_throttle {
                return 0;
            }
        } else {
            self.throttle_counter = 0;
        }

        if has_direction_changed {
            self.velocity = MIN_VELOCITY;
        } else if is_scrolling_quickly {
            self.velocity = (self.velocity + ACCELERATION).min(MAX_VELOCITY);
        } else {
            self.velocity = MIN_VELOCITY;
        }

        self.velocity.round().clamp(MIN_VELOCITY, MAX_VELOCITY) as usize
    }
Call this on every scroll event (mouse wheel, key, etc).
Returns the number of lines to scroll for this event.
crates/turborepo-ui/src/tui/scroll.rs