use std::io;
use ratatui::DefaultTerminal;
use ratatui::widgets::TableState;
use super::app::App;
use super::render::render;
pub struct Session {
terminal: DefaultTerminal,
table: TableState,
}
impl Session {
pub fn open() -> io::Result<Self> {
ratatui::try_init().map(|terminal| Self {
terminal,
table: TableState::new(),
})
}
pub fn draw(&mut self, app: &App) -> io::Result<()> {
let table = &mut self.table;
self.terminal
.draw(|frame| render(frame, app, table))
.map(|_| ())
}
}
impl Drop for Session {
fn drop(&mut self) {
ratatui::restore();
}
}