docs(examples): move user-input example to examples folder (#1659)

This commit is contained in:
Orhun Parmaksız 2025-02-07 04:45:56 +03:00 committed by GitHub
parent dbfb7da9e3
commit 910d16e63a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 58 additions and 34 deletions

9
Cargo.lock generated
View File

@ -3853,6 +3853,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "user-input"
version = "0.0.0"
dependencies = [
"color-eyre",
"crossterm",
"ratatui",
]
[[package]] [[package]]
name = "utf16_iter" name = "utf16_iter"
version = "1.0.5" version = "1.0.5"

View File

@ -118,6 +118,10 @@ Shows how to handle mouse events. [Source](./apps/mouse-drawing/).
Shows how to create a minimal application. [Source](./apps/minimal/). 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 ## 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,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

View File

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

View File

@ -1,32 +1,25 @@
//! # [Ratatui] User Input example /// A simple example demonstrating how to handle user input.
//! ///
//! The latest version of this example is available in the [examples] folder in the repository. /// 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
//! Please note that the examples are designed to be run against the `main` branch of the Github /// some to get started.
//! 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. /// This is a very simple example:
//! /// * An input box always focused. Every character you type is registered here.
//! See the [examples readme] for more information on finding examples that match the version of the /// * An entered character is inserted at the cursor position.
//! library you are using. /// * Pressing Backspace erases the left character before the cursor position
//! /// * Pressing Enter pushes the current input in the history of previous messages.
//! [Ratatui]: https://github.com/ratatui/ratatui ///
//! [examples]: https://github.com/ratatui/ratatui/blob/main/examples /// **Note:** as this is a relatively simple example unicode characters are unsupported and
//! [examples readme]: https://github.com/ratatui/ratatui/blob/main/examples/README.md /// their use will result in undefined behaviour.
///
// A simple example demonstrating how to handle user input. This is a bit out of the scope of /// See also <https://github.com/rhysd/tui-textarea> and <https://github.com/sayanarijit/tui-input>/
// the library as it does not provide any input handling out of the box. However, it may helps ///
// some to get started. /// 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
// This is a very simple example: /// release.
// * An input box always focused. Every character you type is registered here. ///
// * An entered character is inserted at the cursor position. /// [`latest`]: https://github.com/ratatui/ratatui/tree/latest
// * 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/
use color_eyre::Result; use color_eyre::Result;
use ratatui::{ use ratatui::{
crossterm::event::{self, Event, KeyCode, KeyEventKind}, crossterm::event::{self, Event, KeyCode, KeyEventKind},

View File

@ -152,11 +152,6 @@ name = "scrollbar-widget"
required-features = ["crossterm"] required-features = ["crossterm"]
doc-scrape-examples = true doc-scrape-examples = true
[[example]]
name = "user_input"
required-features = ["crossterm"]
doc-scrape-examples = true
[[example]] [[example]]
name = "widget_impl" name = "widget_impl"
required-features = ["crossterm", "unstable-widget-ref"] required-features = ["crossterm", "unstable-widget-ref"]