From 104d6a6c2b2a06afb076dd339ee6a7900b65f365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Orhun=20Parmaks=C4=B1z?= Date: Wed, 5 Feb 2025 03:39:24 +0300 Subject: [PATCH] docs(examples): move custom-widget example to examples folder (#1644) --- Cargo.lock | 9 ++++++++ examples/README.md | 4 ++++ examples/apps/custom-widget/Cargo.toml | 14 +++++++++++ examples/apps/custom-widget/README.md | 9 ++++++++ .../apps/custom-widget/src/main.rs | 23 +++++++------------ ratatui/Cargo.toml | 5 ---- 6 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 examples/apps/custom-widget/Cargo.toml create mode 100644 examples/apps/custom-widget/README.md rename ratatui/examples/custom_widget.rs => examples/apps/custom-widget/src/main.rs (91%) diff --git a/Cargo.lock b/Cargo.lock index fbb34774..d5ed6840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -751,6 +751,15 @@ dependencies = [ "phf", ] +[[package]] +name = "custom-widget" +version = "0.0.0" +dependencies = [ + "color-eyre", + "crossterm", + "ratatui", +] + [[package]] name = "darling" version = "0.20.10" diff --git a/examples/README.md b/examples/README.md index e572f894..98a00b11 100644 --- a/examples/README.md +++ b/examples/README.md @@ -73,6 +73,10 @@ This interactive example shows how different constraints can be used to layout w This example shows different types of constraints. [Source](./apps/constraints/). +## Custom widget demo + +This example shows how to create a custom widget that can be interacted with the mouse. [Source](./apps/custom-widget/). + ## Flex demo This interactive example shows how to use the flex layouts. [Source](./apps/flex/). diff --git a/examples/apps/custom-widget/Cargo.toml b/examples/apps/custom-widget/Cargo.toml new file mode 100644 index 00000000..59692fbb --- /dev/null +++ b/examples/apps/custom-widget/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "custom-widget" +publish = false +license.workspace = true +edition.workspace = true +rust-version.workspace = true + +[dependencies] +color-eyre.workspace = true +crossterm.workspace = true +ratatui.workspace = true + +[lints] +workspace = true diff --git a/examples/apps/custom-widget/README.md b/examples/apps/custom-widget/README.md new file mode 100644 index 00000000..d3e52f3e --- /dev/null +++ b/examples/apps/custom-widget/README.md @@ -0,0 +1,9 @@ +# Custom widget demo + +This example shows how to create a custom widget that can be interacted with the mouse. + +To run this demo: + +```shell +cargo run -p custom-widget +``` diff --git a/ratatui/examples/custom_widget.rs b/examples/apps/custom-widget/src/main.rs similarity index 91% rename from ratatui/examples/custom_widget.rs rename to examples/apps/custom-widget/src/main.rs index 0c5bf459..f87dedf1 100644 --- a/ratatui/examples/custom_widget.rs +++ b/examples/apps/custom-widget/src/main.rs @@ -1,18 +1,11 @@ -//! # [Ratatui] Custom Widget example -//! -//! 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 - +/// A Ratatui example that demonstrates how to create a custom widget that can be interacted +/// with using the mouse. +/// +/// 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 use std::{io::stdout, ops::ControlFlow, time::Duration}; use color_eyre::Result; diff --git a/ratatui/Cargo.toml b/ratatui/Cargo.toml index 0d9e6641..ea039242 100644 --- a/ratatui/Cargo.toml +++ b/ratatui/Cargo.toml @@ -142,11 +142,6 @@ bench = false name = "main" harness = false -[[example]] -name = "custom_widget" -required-features = ["crossterm"] -doc-scrape-examples = true - [[example]] name = "docsrs" required-features = ["crossterm"]