Skip to content

Commit 64f0481

Browse files
committed
Remove readline builder configuration
1 parent 0bce5a7 commit 64f0481

8 files changed

Lines changed: 43 additions & 129 deletions

File tree

‎examples/confirm/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[dependencies]
88
anyhow = { workspace = true }
9-
promkit = { path = "../../promkit", features = ["runtime"] }
9+
promkit = { path = "../../promkit", features = ["runtime", "validate"] }
1010
readline-example = { package = "readline", path = "../readline" }
1111
tokio = { workspace = true }
1212

‎examples/confirm/src/confirm.rs‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use promkit::Prompt;
1+
use promkit::{validate::ValidatorManager, Prompt};
22
use readline_example::Readline;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {
6-
let ret = Readline::default()
7-
.prefix("Do you have a pet? (y/n) ")
8-
.validator(
9-
|text| ["yes", "no", "y", "n", "Y", "N"].contains(&text),
10-
|_| "Please type 'y' or 'n' as an answer".into(),
11-
)
12-
.run()
13-
.await?;
6+
let mut prompt = Readline::default();
7+
prompt.readline.config.prefix = "Do you have a pet? (y/n) ".into();
8+
prompt.validator = Some(ValidatorManager::new(
9+
|text| ["yes", "no", "y", "n", "Y", "N"].contains(&text),
10+
|_| "Please type 'y' or 'n' as an answer".into(),
11+
));
12+
13+
let ret = prompt.run().await?;
1414
println!("result: {:?}", ret);
1515
Ok(())
1616
}

‎examples/password/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[dependencies]
88
anyhow = { workspace = true }
9-
promkit = { path = "../../promkit", features = ["runtime"] }
9+
promkit = { path = "../../promkit", features = ["runtime", "validate", "text"] }
1010
readline-example = { package = "readline", path = "../readline" }
1111
tokio = { workspace = true }
1212

‎examples/password/src/password.rs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
use promkit::Prompt;
1+
use promkit::{validate::ValidatorManager, widgets::text::Text, Prompt};
22
use readline_example::Readline;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {
6-
let ret = Readline::default()
7-
.title("Put your password")
8-
.mask('*')
9-
.validator(
10-
|text| 4 < text.len() && text.len() < 10,
11-
|text| format!("Length must be over 4 and within 10 but got {}", text.len()),
12-
)
13-
.run()
14-
.await?;
6+
let mut prompt = Readline::default();
7+
prompt.title.text = Text::from("Put your password");
8+
prompt.readline.config.mask = Some('*');
9+
prompt.validator = Some(ValidatorManager::new(
10+
|text| 4 < text.len() && text.len() < 10,
11+
|text| format!("Length must be over 4 and within 10 but got {}", text.len()),
12+
));
13+
14+
let ret = prompt.run().await?;
1515
println!("result: {:?}", ret);
1616
Ok(())
1717
}

‎examples/readline/src/lib.rs‎

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use promkit::{
1212
Widget,
1313
},
1414
suggest::Suggest,
15-
validate::{ErrorMessageGenerator, Validator, ValidatorManager},
15+
validate::ValidatorManager,
1616
widgets::{
1717
listbox::{self, Listbox},
18-
text::{self, Text},
19-
text_editor::{self, History},
18+
text, text_editor,
2019
},
2120
Prompt, Signal,
2221
};
@@ -158,80 +157,6 @@ impl Prompt for Readline {
158157
}
159158

160159
impl Readline {
161-
pub fn title<T: AsRef<str>>(mut self, text: T) -> Self {
162-
self.title.text = Text::from(text);
163-
self
164-
}
165-
166-
pub fn title_style(mut self, style: ContentStyle) -> Self {
167-
self.title.config.style = Some(style);
168-
self
169-
}
170-
171-
pub fn enable_suggest(mut self, suggest: Suggest) -> Self {
172-
self.suggest = Some(suggest);
173-
self
174-
}
175-
176-
pub fn enable_history(mut self) -> Self {
177-
self.readline.history = Some(History::default());
178-
self
179-
}
180-
181-
pub fn prefix<T: AsRef<str>>(mut self, prefix: T) -> Self {
182-
self.readline.config.prefix = prefix.as_ref().to_string();
183-
self
184-
}
185-
186-
pub fn mask(mut self, mask: char) -> Self {
187-
self.readline.config.mask = Some(mask);
188-
self
189-
}
190-
191-
pub fn prefix_style(mut self, style: ContentStyle) -> Self {
192-
self.readline.config.prefix_style = style;
193-
self
194-
}
195-
196-
pub fn active_char_style(mut self, style: ContentStyle) -> Self {
197-
self.readline.config.active_char_style = style;
198-
self
199-
}
200-
201-
pub fn inactive_char_style(mut self, style: ContentStyle) -> Self {
202-
self.readline.config.inactive_char_style = style;
203-
self
204-
}
205-
206-
pub fn edit_mode(mut self, mode: text_editor::Mode) -> Self {
207-
self.readline.config.edit_mode = mode;
208-
self
209-
}
210-
211-
pub fn word_break_chars(mut self, characters: HashSet<char>) -> Self {
212-
self.readline.config.word_break_chars = characters;
213-
self
214-
}
215-
216-
pub fn text_editor_lines(mut self, lines: usize) -> Self {
217-
self.readline.config.lines = Some(lines);
218-
self
219-
}
220-
221-
pub fn evaluator(mut self, evaluator: Evaluator<Self>) -> Self {
222-
self.evaluator = evaluator;
223-
self
224-
}
225-
226-
pub fn validator(
227-
mut self,
228-
validator: Validator<str>,
229-
error_message_generator: ErrorMessageGenerator<str>,
230-
) -> Self {
231-
self.validator = Some(ValidatorManager::new(validator, error_message_generator));
232-
self
233-
}
234-
235160
async fn render(&mut self) -> anyhow::Result<()> {
236161
match self.renderer.as_ref() {
237162
Some(renderer) => {

‎examples/readline/src/readline.rs‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use promkit::{suggest::Suggest, Prompt};
1+
use promkit::{suggest::Suggest, validate::ValidatorManager, widgets::text::Text, Prompt};
22
use readline::Readline;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {
6-
let ret = Readline::default()
7-
.title("Hi!")
8-
.enable_suggest(Suggest::from_iter([
9-
"apple",
10-
"applet",
11-
"application",
12-
"banana",
13-
]))
14-
.validator(
15-
|text| text.len() > 10,
16-
|text| format!("Length must be over 10 but got {}", text.len()),
17-
)
18-
.run()
19-
.await?;
6+
let mut prompt = Readline::default();
7+
prompt.title.text = Text::from("Hi!");
8+
prompt.suggest = Some(Suggest::from_iter([
9+
"apple",
10+
"applet",
11+
"application",
12+
"banana",
13+
]));
14+
prompt.validator = Some(ValidatorManager::new(
15+
|text| text.len() > 10,
16+
|text| format!("Length must be over 10 but got {}", text.len()),
17+
));
18+
19+
let ret = prompt.run().await?;
2020
println!("result: {:?}", ret);
2121
Ok(())
2222
}

‎tests/readline/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[dependencies]
88
anyhow = { workspace = true }
9-
promkit = { path = "../../promkit", features = ["runtime", "suggest"] }
9+
promkit = { path = "../../promkit", features = ["runtime", "text"] }
1010
readline-example = { package = "readline", path = "../../examples/readline" }
1111
tokio = { workspace = true }
1212

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
1-
use promkit::{suggest::Suggest, Prompt};
1+
use promkit::Prompt;
22
use readline_example::Readline;
33

44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {
66
println!("Build completed successfully.");
77

8-
Readline::default()
9-
.title("Hi!")
10-
.enable_suggest(Suggest::from_iter([
11-
"apple",
12-
"applet",
13-
"application",
14-
"banana",
15-
]))
16-
.validator(
17-
|text| text.len() > 10,
18-
|text| format!("Length must be over 10 but got {}", text.len()),
19-
)
20-
.run()
21-
.await?;
8+
let mut prompt = Readline::default();
9+
prompt.title.text = "Hi!".into();
10+
prompt.run().await?;
2211
Ok(())
2312
}

0 commit comments

Comments
 (0)