docs(examples): move minimal example to examples folder (#1649)

This commit is contained in:
Orhun Parmaksız 2025-02-05 21:11:57 +03:00 committed by GitHub
parent f5fc8197ff
commit bb94d1c0fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 71 additions and 63 deletions

9
Cargo.lock generated
View File

@ -1792,6 +1792,14 @@ dependencies = [
"autocfg 1.4.0", "autocfg 1.4.0",
] ]
[[package]]
name = "minimal"
version = "0.0.0"
dependencies = [
"crossterm",
"ratatui",
]
[[package]] [[package]]
name = "minimal-lexical" name = "minimal-lexical"
version = "0.2.1" version = "0.2.1"
@ -2514,7 +2522,6 @@ dependencies = [
"rstest", "rstest",
"serde", "serde",
"serde_json", "serde_json",
"strum",
"time", "time",
"tokio", "tokio",
"tracing", "tracing",

View File

@ -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/). Shows how to handle mouse events. [Source](./apps/mouse-drawing/).
## Minimal demo
Shows how to create a minimal application. [Source](./apps/minimal/).
## Weather demo ## Weather demo
Shows how to render weather data using barchart widget. [Source](./apps/weather/). Shows how to render weather data using barchart widget. [Source](./apps/weather/).

View File

@ -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

View File

@ -0,0 +1,9 @@
# Minimal demo
This example shows how to create a minimal application.
To run this demo:
```shell
cargo run -p minimal
```

View File

@ -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());
}

View File

@ -780,29 +780,20 @@ mod tests {
#[test] #[test]
fn test_render_wrapped_paragraph_with_whitespace_only_line() { 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 paragraph = Paragraph::new(text.clone()).wrap(Wrap { trim: false });
let trimmed_paragraph = Paragraph::new(text).wrap(Wrap { trim: true }); let trimmed_paragraph = Paragraph::new(text).wrap(Wrap { trim: true });
test_case( test_case(
&paragraph, &paragraph,
&Buffer::with_lines([ &Buffer::with_lines(["A", " ", "B", " a", "C"]),
"A",
" ",
"B",
" a",
"C",
]),
); );
test_case( test_case(
&trimmed_paragraph, &trimmed_paragraph,
&Buffer::with_lines([ &Buffer::with_lines(["A", "", "B", "a", "C"]),
"A",
"",
"B",
"a",
"C",
]),
); );
} }

View File

@ -105,7 +105,6 @@ ratatui-crossterm = { workspace = true, optional = true }
ratatui-termwiz = { workspace = true, optional = true } ratatui-termwiz = { workspace = true, optional = true }
ratatui-widgets = { workspace = true } ratatui-widgets = { workspace = true }
serde = { workspace = true, optional = true } serde = { workspace = true, optional = true }
strum.workspace = true
time = { version = "0.3.37", optional = true, features = ["local-offset"] } time = { version = "0.3.37", optional = true, features = ["local-offset"] }
# See <https://github.com/ratatui/ratatui/issues/1271> for information about why we pin unicode-width # See <https://github.com/ratatui/ratatui/issues/1271> for information about why we pin unicode-width
unicode-width.workspace = true unicode-width.workspace = true
@ -157,12 +156,6 @@ name = "list-widget"
required-features = ["crossterm"] required-features = ["crossterm"]
doc-scrape-examples = true 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]] [[example]]
name = "modifiers" name = "modifiers"
required-features = ["crossterm"] required-features = ["crossterm"]

View File

@ -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());
}