diff --git a/Cargo.lock b/Cargo.lock index 9cb6ff9a..c8d62cef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1792,6 +1792,14 @@ dependencies = [ "autocfg 1.4.0", ] +[[package]] +name = "minimal" +version = "0.0.0" +dependencies = [ + "crossterm", + "ratatui", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2514,7 +2522,6 @@ dependencies = [ "rstest", "serde", "serde_json", - "strum", "time", "tokio", "tracing", diff --git a/examples/README.md b/examples/README.md index 6114090c..4f992753 100644 --- a/examples/README.md +++ b/examples/README.md @@ -97,6 +97,10 @@ Shows how to render a form with input fields. [Source](./apps/input-form/). Shows how to handle mouse events. [Source](./apps/mouse-drawing/). +## Minimal demo + +Shows how to create a minimal application. [Source](./apps/minimal/). + ## Weather demo Shows how to render weather data using barchart widget. [Source](./apps/weather/). diff --git a/examples/apps/minimal/Cargo.toml b/examples/apps/minimal/Cargo.toml new file mode 100644 index 00000000..a4154aa8 --- /dev/null +++ b/examples/apps/minimal/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "minimal" +publish = false +license.workspace = true +edition.workspace = true +rust-version.workspace = true + +[dependencies] +crossterm.workspace = true +ratatui.workspace = true + +[lints] +workspace = true diff --git a/examples/apps/minimal/README.md b/examples/apps/minimal/README.md new file mode 100644 index 00000000..105dc996 --- /dev/null +++ b/examples/apps/minimal/README.md @@ -0,0 +1,9 @@ +# Minimal demo + +This example shows how to create a minimal application. + +To run this demo: + +```shell +cargo run -p minimal +``` diff --git a/examples/apps/minimal/src/main.rs b/examples/apps/minimal/src/main.rs new file mode 100644 index 00000000..f2a88b6a --- /dev/null +++ b/examples/apps/minimal/src/main.rs @@ -0,0 +1,31 @@ +/// A minimal example of a Ratatui application. +/// +/// This is a bare minimum example. There are many approaches to running an application loop, +/// so this is not meant to be prescriptive. See the [examples] folder for more complete +/// examples. In particular, the [hello-world] example is a good starting point. +/// +/// This example runs with the Ratatui library code in the branch that you are currently +/// reading. See the [`latest`] branch for the code which works with the most recent Ratatui +/// release. +/// +/// [`latest`]: https://github.com/ratatui/ratatui/tree/latest +/// [examples]: https://github.com/ratatui/ratatui/blob/main/examples +/// [hello-world]: https://github.com/ratatui/ratatui/blob/main/examples/apps/hello-world +use crossterm::event::{self, Event}; +use ratatui::{text::Text, Frame}; + +fn main() { + let mut terminal = ratatui::init(); + loop { + terminal.draw(draw).expect("failed to draw frame"); + if matches!(event::read().expect("failed to read event"), Event::Key(_)) { + break; + } + } + ratatui::restore(); +} + +fn draw(frame: &mut Frame) { + let text = Text::raw("Hello World!"); + frame.render_widget(text, frame.area()); +} diff --git a/ratatui-widgets/src/paragraph.rs b/ratatui-widgets/src/paragraph.rs index b0f049c9..cce3cb10 100644 --- a/ratatui-widgets/src/paragraph.rs +++ b/ratatui-widgets/src/paragraph.rs @@ -780,29 +780,20 @@ mod tests { #[test] fn test_render_wrapped_paragraph_with_whitespace_only_line() { - let text: Text = ["A", " ", "B", " a", "C"].into_iter().map(Line::from).collect(); + let text: Text = ["A", " ", "B", " a", "C"] + .into_iter() + .map(Line::from) + .collect(); let paragraph = Paragraph::new(text.clone()).wrap(Wrap { trim: false }); let trimmed_paragraph = Paragraph::new(text).wrap(Wrap { trim: true }); test_case( ¶graph, - &Buffer::with_lines([ - "A", - " ", - "B", - " a", - "C", - ]), + &Buffer::with_lines(["A", " ", "B", " a", "C"]), ); test_case( &trimmed_paragraph, - &Buffer::with_lines([ - "A", - "", - "B", - "a", - "C", - ]), + &Buffer::with_lines(["A", "", "B", "a", "C"]), ); } diff --git a/ratatui/Cargo.toml b/ratatui/Cargo.toml index a5161fcb..2954e9e1 100644 --- a/ratatui/Cargo.toml +++ b/ratatui/Cargo.toml @@ -105,7 +105,6 @@ ratatui-crossterm = { workspace = true, optional = true } ratatui-termwiz = { workspace = true, optional = true } ratatui-widgets = { workspace = true } serde = { workspace = true, optional = true } -strum.workspace = true time = { version = "0.3.37", optional = true, features = ["local-offset"] } # See for information about why we pin unicode-width unicode-width.workspace = true @@ -157,12 +156,6 @@ name = "list-widget" required-features = ["crossterm"] doc-scrape-examples = true -[[example]] -name = "minimal" -required-features = ["crossterm"] -# prefer to show the more featureful examples in the docs -doc-scrape-examples = false - [[example]] name = "modifiers" required-features = ["crossterm"] diff --git a/ratatui/examples/minimal.rs b/ratatui/examples/minimal.rs deleted file mode 100644 index 06b859d2..00000000 --- a/ratatui/examples/minimal.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! # [Ratatui] Minimal example -//! -//! This is a bare minimum example. There are many approaches to running an application loop, so -//! this is not meant to be prescriptive. See the [examples] folder for more complete examples. -//! In particular, the [hello-world] example is a good starting point. -//! -//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples -//! [hello-world]: https://github.com/ratatui/ratatui/blob/main/examples/hello_world.rs -//! -//! The latest version of this example is available in the [examples] folder in the repository. -//! -//! Please note that the examples are designed to be run against the `main` branch of the Github -//! repository. This means that you may not be able to compile with the latest release version on -//! crates.io, or the one that you have installed locally. -//! -//! See the [examples readme] for more information on finding examples that match the version of the -//! library you are using. -//! -//! [Ratatui]: https://github.com/ratatui/ratatui -//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples -//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md - -use crossterm::event::{self, Event}; -use ratatui::{text::Text, Frame}; - -fn main() { - let mut terminal = ratatui::init(); - loop { - terminal.draw(draw).expect("failed to draw frame"); - if matches!(event::read().expect("failed to read event"), Event::Key(_)) { - break; - } - } - ratatui::restore(); -} - -fn draw(frame: &mut Frame) { - let text = Text::raw("Hello World!"); - frame.render_widget(text, frame.area()); -}