From e5cdef3901e934bef6f3b7bce71198c3282ef34b Mon Sep 17 00:00:00 2001 From: ynqa Date: Mon, 12 Feb 2024 17:18:10 +0900 Subject: [PATCH] put all example at main --- README.md | 137 +++++++++++++++++++++++++++++++++++++++++++++ examples/README.md | 21 ------- 2 files changed, 137 insertions(+), 21 deletions(-) delete mode 100644 examples/README.md diff --git a/README.md b/README.md index 984074c3..6a131e1a 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,15 @@ having to build complex components for specific use cases. ### Readline +
+Command + ```bash cargo run --example readline ``` +
+
Code @@ -52,6 +57,138 @@ fn main() -> Result { ![readline](https://github.com/ynqa/promkit/assets/6745370/afa75a49-f84b-444f-88e3-3dabca959164) +### Confirm + +
+Command + +```bash +cargo run --example confirm +``` + +
+ +
+Code + +```rust +use promkit::{error::Result, preset::Confirm}; + +fn main() -> Result { + let mut p = Confirm::new("Do you like programming?").prompt()?; + println!("result: {:?}", p.run()?); + Ok(()) +} +``` +
+
+ +![confirm](https://github.com/ynqa/promkit/assets/6745370/bcc17774-c516-4961-95dd-13036cec5137) + +### Password + +
+Command + +```bash +cargo run --example password +``` + +
+ +
+Code + +```rust +use promkit::{error::Result, preset::Password}; + +fn main() -> Result { + let mut p = Password::default() + .title("Put your password") + .validator( + |text| 4 < text.len() && text.len() < 10, + |text| format!("Length must be over 4 and within 10 but got {}", text.len()), + ) + .prompt()?; + println!("result: {:?}", p.run()?); + Ok(()) +} +``` +
+
+ +![password](https://github.com/ynqa/promkit/assets/6745370/15bc9dc7-8e17-4c57-8634-9dcc55effd60) + +### Select + +
+Command + +```bash +cargo run --example select +``` +
+ +
+Code + +```rust +use promkit::{error::Result, preset::Select}; + +fn main() -> Result { + let mut p = Select::new(0..100) + .title("What number do you like?") + .lines(5) + .prompt()?; + println!("result: {:?}", p.run()?); + Ok(()) +} +``` +
+
+ +![select](https://github.com/ynqa/promkit/assets/6745370/bdf3338a-5647-4e6d-88a6-0c79834992ca) + +### QuerySelect + +
+Command + +```bash +cargo run --example queryselect +``` +
+ +
+Code + +```rust +use promkit::{error::Result, preset::QuerySelect}; + +fn main() -> Result { + let mut p = QuerySelect::new(0..100, |text, items| -> Vec { + text.parse::() + .map(|query| { + items + .iter() + .filter(|num| query <= num.parse::().unwrap_or_default()) + .map(|num| num.to_string()) + .collect::>() + }) + .unwrap_or(items.clone()) + }) + .title("What number do you like?") + .listbox_lines(5) + .prompt()?; + println!("result: {:?}", p.run()?); + Ok(()) +} +``` +
+
+ +![queryselect](https://github.com/ynqa/promkit/assets/6745370/1abdd5c0-2c3b-47d3-916e-386fd4f50779) + ## Why *promkit*? Similar libraries in this category include the following: diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index 42412290..00000000 --- a/examples/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Examples - -## Readline - -![readline](https://github.com/ynqa/promkit/assets/6745370/afa75a49-f84b-444f-88e3-3dabca959164) - -## Select - -![select](https://github.com/ynqa/promkit/assets/6745370/bdf3338a-5647-4e6d-88a6-0c79834992ca) - -## Confirm - -![confirm](https://github.com/ynqa/promkit/assets/6745370/bcc17774-c516-4961-95dd-13036cec5137) - -## Password - -![password](https://github.com/ynqa/promkit/assets/6745370/15bc9dc7-8e17-4c57-8634-9dcc55effd60) - -## QuerySelect - -![queryselect](https://github.com/ynqa/promkit/assets/6745370/1abdd5c0-2c3b-47d3-916e-386fd4f50779)