use std::io; use std::time::{Duration, Instant}; use crossterm::event; use crossterm::event::{Event, KeyCode}; use tui::backend::Backend; use tui::{Frame, Terminal}; use crate::client::Client; use crate::constants::*; use crate::ui_screens::ScreenResult; pub struct GameScreen { client: Client, } impl GameScreen { pub fn new(client: Client) -> Self { Self { client } } pub async fn show( mut self, terminal: &mut Terminal, ) -> io::Result { let mut last_tick = Instant::now(); loop { terminal.draw(|f| self.ui(f))?; let timeout = TICK_RATE .checked_sub(last_tick.elapsed()) .unwrap_or_else(|| Duration::from_secs(0)); if crossterm::event::poll(timeout)? { if let Event::Key(key) = event::read()? { match key.code { KeyCode::Char('q') => return Ok(ScreenResult::Canceled), _ => {} } } } if last_tick.elapsed() >= TICK_RATE { last_tick = Instant::now(); } } } fn ui(&mut self, f: &mut Frame) {} }