mirror of
https://github.com/ratatui/ratatui.git
synced 2025-09-27 04:50:46 +00:00
docs(examples): move minimal example to examples folder (#1649)
This commit is contained in:
parent
f5fc8197ff
commit
bb94d1c0fa
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -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",
|
||||
|
@ -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/).
|
||||
|
13
examples/apps/minimal/Cargo.toml
Normal file
13
examples/apps/minimal/Cargo.toml
Normal 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
|
9
examples/apps/minimal/README.md
Normal file
9
examples/apps/minimal/README.md
Normal 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
|
||||
```
|
31
examples/apps/minimal/src/main.rs
Normal file
31
examples/apps/minimal/src/main.rs
Normal 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());
|
||||
}
|
@ -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"]),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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 <https://github.com/ratatui/ratatui/issues/1271> 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"]
|
||||
|
@ -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());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user