Crates.io | rat-fps |
lib.rs | rat-fps |
version | 0.1.1 |
source | src |
created_at | 2024-11-28 20:35:08.153323 |
updated_at | 2024-11-28 20:59:29.797156 |
description | Widget to show FPS in ratatui |
homepage | |
repository | |
max_upload_size | |
id | 1464980 |
size | 23,206 |
A Widget for use with Ratatui to display FPS
use std::{error::Error, time::Duration};
use rat_fps::FPS;
use ratatui::crossterm::{self, event::{Event, KeyCode, KeyEvent}};
fn main() -> Result<(), Box<dyn Error>> {
let mut term = ratatui::init();
let mut keep_running = true;
let mut fps = FPS::new()?;
while keep_running {
term.draw(|f|{
//render the fps
f.render_widget(&mut fps, f.area());
})?;
//wait roughly to enable rpughly atleast 60fps if possible,
// note what you do after the poll might reduce fps if not fast enough,
// in such cases it is adviced to have a higher wait for fps,
//roughly 30+ above expected
if crossterm::event::poll(Duration::from_millis(fps.wait_for_fps(60)?))? {
if let Event::Key(KeyEvent{
code: KeyCode::Char('q'), ..}) = crossterm::event::read()? {
keep_running = false;
}
}
}
ratatui::restore();
Ok(())
}