diff --git a/Cargo.lock b/Cargo.lock index c20984ec..8bf38b26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3853,6 +3853,15 @@ dependencies = [ "serde", ] +[[package]] +name = "user-input" +version = "0.0.0" +dependencies = [ + "color-eyre", + "crossterm", + "ratatui", +] + [[package]] name = "utf16_iter" version = "1.0.5" diff --git a/examples/README.md b/examples/README.md index 00c0d7b4..10d2e0fe 100644 --- a/examples/README.md +++ b/examples/README.md @@ -118,6 +118,10 @@ Shows how to handle mouse events. [Source](./apps/mouse-drawing/). Shows how to create a minimal application. [Source](./apps/minimal/). +## User input demo + +Shows how to handle user input. [Source](./apps/user-input/). + ## Weather demo Shows how to render weather data using barchart widget. [Source](./apps/weather/). diff --git a/examples/apps/user-input/Cargo.toml b/examples/apps/user-input/Cargo.toml new file mode 100644 index 00000000..5d3ce0da --- /dev/null +++ b/examples/apps/user-input/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "user-input" +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/user-input/README.md b/examples/apps/user-input/README.md new file mode 100644 index 00000000..c263afa6 --- /dev/null +++ b/examples/apps/user-input/README.md @@ -0,0 +1,9 @@ +# User input demo + +This example shows how to handle user input. + +To run this demo: + +```shell +cargo run -p user-input +``` diff --git a/ratatui/examples/user_input.rs b/examples/apps/user-input/src/main.rs similarity index 83% rename from ratatui/examples/user_input.rs rename to examples/apps/user-input/src/main.rs index 2d4b0b43..e67f72fe 100644 --- a/ratatui/examples/user_input.rs +++ b/examples/apps/user-input/src/main.rs @@ -1,32 +1,25 @@ -//! # [Ratatui] User Input 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 simple example demonstrating how to handle user input. This is a bit out of the scope of -// the library as it does not provide any input handling out of the box. However, it may helps -// some to get started. -// -// This is a very simple example: -// * An input box always focused. Every character you type is registered here. -// * An entered character is inserted at the cursor position. -// * Pressing Backspace erases the left character before the cursor position -// * Pressing Enter pushes the current input in the history of previous messages. **Note: ** as -// this is a relatively simple example unicode characters are unsupported and their use will -// result in undefined behaviour. -// -// See also https://github.com/rhysd/tui-textarea and https://github.com/sayanarijit/tui-input/ - +/// A simple example demonstrating how to handle user input. +/// +/// This is a bit out of the scope of +/// the library as it does not provide any input handling out of the box. However, it may helps +/// some to get started. +/// +/// This is a very simple example: +/// * An input box always focused. Every character you type is registered here. +/// * An entered character is inserted at the cursor position. +/// * Pressing Backspace erases the left character before the cursor position +/// * Pressing Enter pushes the current input in the history of previous messages. +/// +/// **Note:** as this is a relatively simple example unicode characters are unsupported and +/// their use will result in undefined behaviour. +/// +/// See also and / +/// +/// 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 color_eyre::Result; use ratatui::{ crossterm::event::{self, Event, KeyCode, KeyEventKind}, diff --git a/ratatui/Cargo.toml b/ratatui/Cargo.toml index 604fe0d3..5051ef10 100644 --- a/ratatui/Cargo.toml +++ b/ratatui/Cargo.toml @@ -152,11 +152,6 @@ name = "scrollbar-widget" required-features = ["crossterm"] doc-scrape-examples = true -[[example]] -name = "user_input" -required-features = ["crossterm"] -doc-scrape-examples = true - [[example]] name = "widget_impl" required-features = ["crossterm", "unstable-widget-ref"]