mirror of
https://codeberg.org/JasterV/teatui.git
synced 2026-04-26 18:10:03 +00:00
release: 0.4.0
This commit is contained in:
parent
f32c6e9dd9
commit
29a16f368c
6 changed files with 15 additions and 15 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -1162,7 +1162,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "teatui"
|
name = "teatui"
|
||||||
version = "0.2.1"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
|
|
|
||||||
|
|
@ -101,14 +101,14 @@ pub fn update(model: Model, msg: Message) -> Update<Model, Effect> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_effects(_model: &Model, _effect: Effect) -> Option<Message> {
|
pub fn run_effects(_model: Model, _effect: Effect) -> Option<Message> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Elm-like View function.
|
/// Elm-like View function.
|
||||||
///
|
///
|
||||||
/// Given the current state (read-only), return a drawable widget.
|
/// Given the current state (read-only), return a drawable widget.
|
||||||
pub fn view(model: &Model) -> Paragraph<'static> {
|
pub fn view(model: Model) -> Paragraph<'static> {
|
||||||
let counter = model.counter;
|
let counter = model.counter;
|
||||||
|
|
||||||
let title = Line::from("Ratatui Actor-based Counter")
|
let title = Line::from("Ratatui Actor-based Counter")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "teatui"
|
name = "teatui"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
description = "An elm-like abstraction over Ratatui"
|
description = "An elm-like abstraction over Ratatui"
|
||||||
license.workspace = true
|
license.workspace = true
|
||||||
authors.workspace = true
|
authors.workspace = true
|
||||||
|
|
|
||||||
|
|
@ -18,14 +18,14 @@ pub(crate) fn run<M, Msg, Eff, F>(
|
||||||
) -> Result<(), EffectsError<Msg>>
|
) -> Result<(), EffectsError<Msg>>
|
||||||
where
|
where
|
||||||
Msg: Send + Sync + 'static,
|
Msg: Send + Sync + 'static,
|
||||||
F: Fn(&M, Eff) -> Option<Msg>,
|
F: Fn(M, Eff) -> Option<Msg>,
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
let Ok((model, effect)) = rx.recv() else {
|
let Ok((model, effect)) = rx.recv() else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(msg) = effects_fn(&model, effect) {
|
if let Some(msg) = effects_fn(model, effect) {
|
||||||
tx.send(msg)?;
|
tx.send(msg)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +42,7 @@ where
|
||||||
Msg: Send + Sync + 'static,
|
Msg: Send + Sync + 'static,
|
||||||
Eff: Send + Sync + 'static,
|
Eff: Send + Sync + 'static,
|
||||||
Fut: Future<Output = Option<Msg>> + Send,
|
Fut: Future<Output = Option<Msg>> + Send,
|
||||||
F: Fn(&M, Eff) -> Fut + Send + Sync + 'static,
|
F: Fn(M, Eff) -> Fut + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
let rt = tokio::runtime::Builder::new_current_thread()
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|
@ -56,7 +56,7 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
// We spawn the effect in the tokio reactor so they can run concurrently
|
// We spawn the effect in the tokio reactor so they can run concurrently
|
||||||
let fut = effects_fn(&model, effect);
|
let fut = effects_fn(model, effect);
|
||||||
|
|
||||||
if let Some(msg) = fut.await {
|
if let Some(msg) = fut.await {
|
||||||
let _ = tx.send(msg);
|
let _ = tx.send(msg);
|
||||||
|
|
|
||||||
|
|
@ -87,8 +87,8 @@ where
|
||||||
W: Widget,
|
W: Widget,
|
||||||
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
||||||
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
||||||
VF: Fn(&M) -> W + Send + Sync + 'static,
|
VF: Fn(M) -> W + Send + Sync + 'static,
|
||||||
EF: Fn(&M, Eff) -> Option<Msg> + Send + Sync + 'static,
|
EF: Fn(M, Eff) -> Option<Msg> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| {
|
run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| {
|
||||||
effects::run(effects_fn, effects_rx, update_tx)
|
effects::run(effects_fn, effects_rx, update_tx)
|
||||||
|
|
@ -110,8 +110,8 @@ where
|
||||||
W: Widget,
|
W: Widget,
|
||||||
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
||||||
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
||||||
VF: Fn(&M) -> W + Send + Sync + 'static,
|
VF: Fn(M) -> W + Send + Sync + 'static,
|
||||||
EF: Fn(&M, Eff) -> Fut + Send + Sync + 'static,
|
EF: Fn(M, Eff) -> Fut + Send + Sync + 'static,
|
||||||
Fut: std::future::Future<Output = Option<Msg>> + Send,
|
Fut: std::future::Future<Output = Option<Msg>> + Send,
|
||||||
{
|
{
|
||||||
run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| {
|
run_program(init_fn, update_fn, view_fn, move |effects_rx, update_tx| {
|
||||||
|
|
@ -133,7 +133,7 @@ where
|
||||||
W: Widget,
|
W: Widget,
|
||||||
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
|
||||||
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
UF: Fn(M, Msg) -> Update<M, Eff> + Send + Sync + 'static,
|
||||||
VF: Fn(&M) -> W + Send + Sync + 'static,
|
VF: Fn(M) -> W + Send + Sync + 'static,
|
||||||
SF: FnOnce(
|
SF: FnOnce(
|
||||||
std::sync::mpsc::Receiver<(M, Eff)>,
|
std::sync::mpsc::Receiver<(M, Eff)>,
|
||||||
std::sync::mpsc::Sender<Msg>,
|
std::sync::mpsc::Sender<Msg>,
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ pub(crate) fn run<M, F, W>(
|
||||||
) -> Result<(), ViewError>
|
) -> Result<(), ViewError>
|
||||||
where
|
where
|
||||||
W: Widget,
|
W: Widget,
|
||||||
F: Fn(&M) -> W,
|
F: Fn(M) -> W,
|
||||||
{
|
{
|
||||||
loop {
|
loop {
|
||||||
let widget = view_fn(&model);
|
let widget = view_fn(model);
|
||||||
|
|
||||||
terminal.draw(|frame| frame.render_widget(widget, frame.area()))?;
|
terminal.draw(|frame| frame.render_widget(widget, frame.area()))?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue