Skip to content

Commit

Permalink
chore: update test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
cih9088 committed Oct 26, 2024
1 parent 38f76ca commit 4c87d0c
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion promkit/examples/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::preset::checkbox::Checkbox;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Checkbox::new(vec![
Expand All @@ -15,7 +16,7 @@ fn main() -> anyhow::Result<()> {
])
.title("What are your favorite fruits?")
.checkbox_lines(5)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/confirm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use promkit::preset::confirm::Confirm;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Confirm::new("Do you have a pet?").prompt()?;
let mut p = Confirm::new("Do you have a pet?").prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/form.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::{crossterm::style::Color, preset::form::Form, style::StyleBuilder, text_editor};
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Form::new([
Expand Down Expand Up @@ -39,7 +40,7 @@ fn main() -> anyhow::Result<()> {
lines: Default::default(),
},
])
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::{json::JsonStream, preset::json::Json, serde_json::Deserializer};
use std::io;

fn main() -> anyhow::Result<()> {
let stream = JsonStream::new(
Expand All @@ -23,7 +24,7 @@ fn main() -> anyhow::Result<()> {
let mut p = Json::new(stream)
.title("JSON viewer")
.json_lines(5)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/listbox.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use promkit::preset::listbox::Listbox;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Listbox::new(0..100)
.title("What number do you like?")
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/password.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::preset::password::Password;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Password::default()
Expand All @@ -7,7 +8,7 @@ fn main() -> anyhow::Result<()> {
|text| 4 < text.len() && text.len() < 10,
|text| format!("Length must be over 4 and within 10 but got {}", text.len()),
)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/query_selector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::preset::query_selector::QuerySelector;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = QuerySelector::new(0..100, |text, items| -> Vec<String> {
Expand All @@ -14,7 +15,7 @@ fn main() -> anyhow::Result<()> {
})
.title("What number do you like?")
.listbox_lines(5)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/readline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use promkit::{preset::readline::Readline, suggest::Suggest};
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Readline::default()
Expand All @@ -13,7 +14,7 @@ fn main() -> anyhow::Result<()> {
|text| text.len() > 10,
|text| format!("Length must be over 10 but got {}", text.len()),
)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}
3 changes: 2 additions & 1 deletion promkit/examples/readline_loop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use promkit::preset::readline::Readline;
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Readline::default().prompt()?;
let mut p = Readline::default().prompt(io::stdout())?;

loop {
match p.run() {
Expand Down
3 changes: 2 additions & 1 deletion promkit/examples/tree.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use promkit::{preset::tree::Tree, tree::Node};
use std::io;

fn main() -> anyhow::Result<()> {
let mut p = Tree::new(Node::try_from(&std::env::current_dir()?.join("src"))?)
.title("Select a directory or file")
.tree_lines(10)
.prompt()?;
.prompt(io::stdout())?;
println!("result: {:?}", p.run()?);
Ok(())
}

0 comments on commit 4c87d0c

Please sign in to comment.