Skip to content

Commit

Permalink
simplify tui
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszKielar committed Sep 5, 2024
1 parent 64fffd4 commit 0092886
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ async fn main() -> AppResult<()> {
let mut app: App = App::new(sqlite, event_tx.clone());
app.init().await?;

let mut event_handler = EventHandler::new(250, event_tx, event_rx);

let backend = CrosstermBackend::new(io::stderr());
let terminal = Terminal::new(backend)?;
let events = EventHandler::new(250, event_tx, event_rx);
let mut tui = Tui::new(terminal, events);
let mut tui = Tui::new(terminal);
tui.init()?;

while app.is_running() {
tui.draw(&mut app)?;

let event = tui.events.next().await?;
let event = event_handler.next().await?;
app.handle_events(event).await?;
}

Expand Down
8 changes: 4 additions & 4 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ use crossterm::{
};
use ratatui::{backend::Backend, Terminal};

use crate::{app::App, event::EventHandler, ui, AppResult};
use crate::{app::App, ui, AppResult};

#[derive(Debug)]
pub struct Tui<B: Backend> {
terminal: Terminal<B>,
pub events: EventHandler,
}

impl<B: Backend> Tui<B> {
pub fn new(terminal: Terminal<B>, events: EventHandler) -> Self {
Self { terminal, events }
pub fn new(terminal: Terminal<B>) -> Self {
Self { terminal }
}

pub fn init(&mut self) -> AppResult<()> {
Expand All @@ -37,6 +36,7 @@ impl<B: Backend> Tui<B> {

pub fn draw(&mut self, app: &mut App) -> AppResult<()> {
self.terminal.draw(|frame| ui::render(app, frame))?;

Ok(())
}

Expand Down

0 comments on commit 0092886

Please sign in to comment.