feat: update to ratatui 0.30

This commit is contained in:
JasterV 2026-01-29 02:04:53 +01:00
parent 2aac51341a
commit c11e3a7364
5 changed files with 1063 additions and 338 deletions

1360
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -10,4 +10,4 @@ edition = "2024"
[workspace.dependencies]
color-eyre = "0.6.3"
crossterm = "0.29.0"
ratatui = { version = "0.29.0", features = ["unstable-widget-ref"] }
ratatui = { version = "0.30", features = ["unstable-widget-ref"] }

View file

@ -5,12 +5,11 @@ use ratatui::{
text::Line,
widgets::{Block, Paragraph},
};
use teatui::{Update, View};
use teatui::Update;
fn main() -> Result<()> {
color_eyre::install()?;
let result = teatui::start(|| (Model::default(), None), update, view, run_effects);
result
teatui::start(|| (Model::default(), None), update, view, run_effects)
}
/// Defines the state of the application
@ -109,7 +108,7 @@ pub fn run_effects(_model: &Model, _effect: Effect) -> Result<Option<Message>> {
/// Elm-like View function.
///
/// Given the current state (read-only), return a drawable widget.
pub fn view(model: &Model) -> Result<View> {
pub fn view(model: &Model) -> Result<Paragraph<'static>> {
let counter = model.counter;
let title = Line::from("Ratatui Actor-based Counter")
@ -129,5 +128,5 @@ Press `Esc`, `Ctrl-C` or `q` to stop running."#
.block(Block::bordered().title(title))
.centered();
Ok(View::new(widget))
Ok(widget)
}

View file

@ -33,13 +33,13 @@
//! You can find a folder with example projects in the [examples](https://github.com/JasterV/teatui/tree/main/examples) folder.
use color_eyre::Report;
use color_eyre::Result;
use ratatui::widgets::Widget;
use std::{
sync::mpsc::{Sender, channel},
thread,
};
pub use update::Update;
pub use view::View;
mod effects;
mod events;
@ -58,7 +58,7 @@ mod view;
/// - A `view` function, responsible for constructing the view from the model.
///
/// - An `effects` function responsible for handling side effects.
pub fn start<M, Msg, Eff, IF, UF, VF, EF>(
pub fn start<M, Msg, Eff, W, IF, UF, VF, EF>(
init_fn: IF,
update_fn: UF,
view_fn: VF,
@ -68,9 +68,10 @@ where
M: Clone + Send + Sync + 'static,
Eff: Send + Sync + 'static,
Msg: From<crossterm::event::Event> + Sync + Send + 'static,
W: Widget,
IF: Fn() -> (M, Option<Eff>) + Send + Sync + 'static,
UF: Fn(M, Msg) -> Result<Update<M, Eff>> + Send + Sync + 'static,
VF: Fn(&M) -> Result<View> + Send + Sync + 'static,
VF: Fn(&M) -> Result<W> + Send + Sync + 'static,
EF: Fn(&M, Eff) -> Result<Option<Msg>> + Send + Sync + 'static,
{
let terminal = ratatui::init();

View file

@ -2,34 +2,17 @@
use color_eyre::Result;
use ratatui::DefaultTerminal;
use ratatui::widgets::Widget;
use ratatui::widgets::WidgetRef;
use std::sync::mpsc::Receiver;
/// A thin wrapper around a `ratatui` WidgetRef.
/// It is guaranteed that it will always be possible
/// to construct it from a Widget.
pub struct View(Box<dyn WidgetRef>);
impl View {
pub fn new(widget: impl WidgetRef + 'static) -> Self {
Self(Box::new(widget))
}
}
impl Widget for View {
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
self.0.render_ref(area, buf);
}
}
pub(crate) fn run<M, F>(
pub(crate) fn run<M, F, W>(
mut model: M,
mut terminal: DefaultTerminal,
view_fn: F,
rx: Receiver<M>,
) -> Result<()>
where
F: Fn(&M) -> Result<View>,
W: Widget,
F: Fn(&M) -> Result<W>,
{
loop {
let widget = view_fn(&model)?;