Add more examples
This commit is contained in:
parent
affcc36bc0
commit
a2abf6b335
|
@ -26,7 +26,7 @@ rand = "0.8"
|
|||
rand_chacha = "0.3"
|
||||
|
||||
regex = "1.5" # examples/{prompt_module,macro}.rs
|
||||
fuzzy-matcher = "0.3" # examples/file.rs
|
||||
fuzzy-matcher = "0.3" # examples/file_auto_complete.rs
|
||||
|
||||
[features]
|
||||
default = ["crossterm", "smallvec"]
|
||||
|
|
7
examples/confirm.rs
Normal file
7
examples/confirm.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
let question = requestty::Question::confirm("anonymous")
|
||||
.message("Do you want to remain anonymous?")
|
||||
.build();
|
||||
|
||||
println!("{:#?}", requestty::prompt_one(question));
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
fn main() {
|
||||
let question = requestty::Question::editor("bio")
|
||||
.message("Please write a short bio of at least 3 lines.")
|
||||
let question = requestty::Question::editor("description")
|
||||
.message("Please enter a short description about yourself")
|
||||
.extension(".md")
|
||||
.validate(|answer, _| {
|
||||
if answer.lines().count() < 3 {
|
||||
Err("Must be at least 3 lines.".into())
|
||||
|
|
14
examples/float.rs
Normal file
14
examples/float.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
fn main() {
|
||||
let question = requestty::Question::float("number")
|
||||
.message("What is your favourite number?")
|
||||
.validate(|num, _| {
|
||||
if num.is_finite() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Please enter a finite number".to_owned())
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
println!("{:#?}", requestty::prompt_one(question));
|
||||
}
|
14
examples/int.rs
Normal file
14
examples/int.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
fn main() {
|
||||
let question = requestty::Question::int("age")
|
||||
.message("What is your age?")
|
||||
.validate(|age, _| {
|
||||
if age > 0 && age < 130 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("You cannot be {} years old!", age))
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
println!("{:#?}", requestty::prompt_one(question));
|
||||
}
|
|
@ -113,9 +113,9 @@ impl<'a> InputBuilder<'a> {
|
|||
/// .build();
|
||||
/// ```
|
||||
///
|
||||
/// For a better example on `auto_complete`, see [`examples/file.rs`]
|
||||
/// For a better example on `auto_complete`, see [`examples/file_auto_complete.rs`]
|
||||
///
|
||||
/// [`examples/file.rs`]: https://github.com/Lutetium-Vanadium/requestty/blob/master/examples/file.rs
|
||||
/// [`examples/file_auto_complete.rs`]: https://github.com/Lutetium-Vanadium/requestty/blob/master/examples/file_auto_complete.rs
|
||||
String; input
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user