mirror of
https://codeberg.org/JasterV/teatui.git
synced 2026-04-26 18:10:03 +00:00
update example
This commit is contained in:
parent
ea5b7c17ca
commit
126ab86f9d
2 changed files with 14 additions and 21 deletions
|
|
@ -4,9 +4,9 @@ use ratatui::{
|
||||||
text::Line,
|
text::Line,
|
||||||
widgets::{Block, Paragraph},
|
widgets::{Block, Paragraph},
|
||||||
};
|
};
|
||||||
use teatui::Update;
|
use teatui::{ProgramError, update::Update};
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
fn main() -> Result<(), ProgramError<Model, Message, Effect>> {
|
||||||
teatui::start(|| (Model::default(), None), update, view, run_effects)
|
teatui::start(|| (Model::default(), None), update, view, run_effects)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,25 +31,18 @@
|
||||||
//! ### Examples
|
//! ### Examples
|
||||||
//!
|
//!
|
||||||
//! You can find a folder with example projects in the [examples](https://github.com/JasterV/teatui/tree/main/examples) folder.
|
//! You can find a folder with example projects in the [examples](https://github.com/JasterV/teatui/tree/main/examples) folder.
|
||||||
|
use effects::EffectsError;
|
||||||
|
use events::EventLoopError;
|
||||||
use ratatui::widgets::Widget;
|
use ratatui::widgets::Widget;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::mpsc::SendError;
|
use std::{sync::mpsc::channel, thread};
|
||||||
use std::{
|
use update::{Update, UpdateError};
|
||||||
sync::mpsc::{Sender, channel},
|
use view::ViewError;
|
||||||
thread,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use update::Update;
|
pub mod effects;
|
||||||
|
pub mod events;
|
||||||
use crate::effects::EffectsError;
|
pub mod update;
|
||||||
use crate::events::EventLoopError;
|
pub mod view;
|
||||||
use crate::update::UpdateError;
|
|
||||||
use crate::view::ViewError;
|
|
||||||
|
|
||||||
mod effects;
|
|
||||||
mod events;
|
|
||||||
mod update;
|
|
||||||
mod view;
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum ProgramError<M, Msg, Eff>
|
pub enum ProgramError<M, Msg, Eff>
|
||||||
|
|
@ -98,8 +91,6 @@ where
|
||||||
{
|
{
|
||||||
let terminal = ratatui::init();
|
let terminal = ratatui::init();
|
||||||
|
|
||||||
let (model, effect) = init_fn();
|
|
||||||
|
|
||||||
// Channel for signaling when a task completes
|
// Channel for signaling when a task completes
|
||||||
let (shutdown_tx, shutdown_rx) = channel::<Result<(), ProgramError<M, Msg, Eff>>>();
|
let (shutdown_tx, shutdown_rx) = channel::<Result<(), ProgramError<M, Msg, Eff>>>();
|
||||||
|
|
||||||
|
|
@ -112,7 +103,8 @@ where
|
||||||
// If the view actor is started after the update actor, it could happen
|
// If the view actor is started after the update actor, it could happen
|
||||||
// that both actors have an out of sync version of the model for a bit.
|
// that both actors have an out of sync version of the model for a bit.
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
let model = model.clone();
|
let (model, _) = init_fn();
|
||||||
|
|
||||||
let shutdown_tx = shutdown_tx.clone();
|
let shutdown_tx = shutdown_tx.clone();
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
|
|
@ -125,6 +117,7 @@ where
|
||||||
|
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
let shutdown_tx = shutdown_tx.clone();
|
let shutdown_tx = shutdown_tx.clone();
|
||||||
|
let (model, effect) = init_fn();
|
||||||
|
|
||||||
move || {
|
move || {
|
||||||
let result = update::run(model, effect, update_fn, update_rx, view_tx, effects_tx)
|
let result = update::run(model, effect, update_fn, update_rx, view_tx, effects_tx)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue