AppEvent (#61)

Extend `events` to provide a `mpsc` channel to send `AppEvent`'s from
anywhere in the app straight to the `App`.
This commit is contained in:
Jens Krause
2025-02-04 15:05:02 +01:00
committed by GitHub
parent d3c436da0b
commit 8f50bc5fc6
9 changed files with 232 additions and 96 deletions

View File

@@ -13,7 +13,7 @@ mod terminal;
mod utils;
mod widgets;
use app::{App, AppArgs};
use app::{App, FromAppArgs};
use args::Args;
use clap::Parser;
use color_eyre::Result;
@@ -30,7 +30,7 @@ async fn main() -> Result<()> {
// get args given by CLI
let args = Args::parse();
let terminal = terminal::setup()?;
let mut terminal = terminal::setup()?;
let events = events::Events::new();
// check persistant storage
@@ -42,9 +42,14 @@ async fn main() -> Result<()> {
storage.load().unwrap_or_default()
};
// merge `Args` and `AppStorage`.
let app_args = AppArgs::from((args, stg));
let app_storage = App::new(app_args).run(terminal, events).await?.to_storage();
let app_storage = App::from(FromAppArgs {
args,
stg,
app_tx: events.get_app_event_tx(),
})
.run(&mut terminal, events)
.await?
.to_storage();
// store app state persistantly
storage.save(app_storage)?;