zilliz 1.3.0

TUI and CLI tool for managing Zilliz Cloud clusters and Milvus operations
Documentation
use std::time::Duration;

use anyhow::Result;
use crossterm::event::{self, KeyEvent};

/// Events that drive the TUI.
pub enum Event {
    /// A keyboard event.
    Key(KeyEvent),
    /// Periodic tick for animations / polling.
    Tick,
    /// Terminal resize.
    #[allow(dead_code)]
    Resize(u16, u16),
}

/// Synchronous event polling (crossterm events + tick timer).
/// Async API responses are handled separately via tokio channels.
pub struct EventLoop {
    tick_rate: Duration,
}

impl EventLoop {
    pub fn new(tick_rate_ms: u64) -> Self {
        Self {
            tick_rate: Duration::from_millis(tick_rate_ms),
        }
    }

    /// Poll for the next event, blocking up to tick_rate.
    pub fn next(&self) -> Result<Event> {
        if event::poll(self.tick_rate)? {
            match event::read()? {
                event::Event::Key(key) => Ok(Event::Key(key)),
                event::Event::Resize(w, h) => Ok(Event::Resize(w, h)),
                _ => Ok(Event::Tick),
            }
        } else {
            Ok(Event::Tick)
        }
    }
}