Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented OrderSelect #16

Merged
merged 33 commits into from Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
645f368
Implemented OrderSelect
NovaliX-Dev Aug 13, 2022
4473889
Added docs
NovaliX-Dev Aug 13, 2022
be019a6
minor fixe
NovaliX-Dev Aug 13, 2022
4c4908f
minor fixe
NovaliX-Dev Aug 13, 2022
e45e139
minor fixes and reformatting
NovaliX-Dev Aug 13, 2022
edc956b
Merge branch 'master' of https://github.com/NovaliX-Dev/requestty
NovaliX-Dev Aug 13, 2022
2eed507
Added example
NovaliX-Dev Aug 13, 2022
ec9e97d
Added index formatting
NovaliX-Dev Aug 14, 2022
cb0293d
added automatic testing
NovaliX-Dev Aug 15, 2022
1b03b98
Updated docs about choices type
NovaliX-Dev Aug 27, 2022
e303a94
Optimized index display
NovaliX-Dev Aug 27, 2022
b4033ae
Updated key handling algorithm and key docs
NovaliX-Dev Aug 27, 2022
7bd6d81
Updated choice input type as separators aren't allowed
NovaliX-Dev Aug 27, 2022
7836936
put insta tests backs
NovaliX-Dev Aug 27, 2022
b300600
Updated docs and added more concrete examples
NovaliX-Dev Aug 27, 2022
7455814
Added comments to the dots that were making the doctests fails
NovaliX-Dev Aug 27, 2022
35bd297
Merge branch 'Lutetium-Vanadium:master' into master
NovaliX-Dev Aug 28, 2022
abf651d
Updated argument type for filter, validate and transform function as …
NovaliX-Dev Aug 28, 2022
743c266
Put the filter, validate and transform functions implementation just …
NovaliX-Dev Aug 28, 2022
3659686
implemented implementation tests
NovaliX-Dev Aug 29, 2022
4faaee4
added a more concrete example on when function
NovaliX-Dev Aug 30, 2022
b49b93e
Fix validate test always failing because validation failed
NovaliX-Dev Aug 30, 2022
4e02352
made integration tests better
NovaliX-Dev Aug 30, 2022
620aee1
removed unused implementation on ListItem
NovaliX-Dev Aug 30, 2022
2c30a53
Removed unnecessary documentation
NovaliX-Dev Aug 30, 2022
79825ad
Updated names to more concrete one in test_filter
NovaliX-Dev Aug 30, 2022
6c177bc
Updated item name to be more explicit
NovaliX-Dev Aug 30, 2022
b51b074
updated some docs
NovaliX-Dev Aug 30, 2022
f3581d9
Fix the check example
NovaliX-Dev Aug 31, 2022
378f506
Updated index so they increment from 1 instead of 0
NovaliX-Dev Sep 1, 2022
684e71d
moved conversion trait from OrderSelectItem to ListItem
NovaliX-Dev Sep 1, 2022
7a413c3
small name fix
NovaliX-Dev Sep 1, 2022
09c9a0b
added snapshots
NovaliX-Dev Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 117
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│  │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 117
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│ 0. 1 │
│ 1. 2 │
│ 2. 3 │
│ 3. 4 │
│ 4. 5 │
│ 5. 6 │
│ 6. 7 │
│ 7. 8 │
│ 8. 9 │
│❯ 9. 0 │
│  │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 117
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│  │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 117
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│  │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 117
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│  │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 124
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│ 10. 10 │
│ 11. 11 │
│ 12. 12 │
│ 13. 13 │
│(Move up and down to reveal more choices) │
│  │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 124
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│ 18. 19 │
│❯ 19. 0 │
│ 0. 1 │
│ 1. 2 │
│ 2. 3 │
│ 3. 4 │
│ 4. 5 │
│ 5. 6 │
│ 6. 7 │
│ 7. 8 │
│ 8. 9 │
│ 9. 10 │
│ 10. 11 │
│ 11. 12 │
│(Move up and down to reveal more choices) │
│  │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 124
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│ 18. 18 │
│ 19. 19 │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│ 10. 10 │
│ 11. 11 │
│(Move up and down to reveal more choices) │
│  │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 124
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│ 18. 18 │
│ 19. 19 │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│ 10. 10 │
│ 11. 11 │
│(Move up and down to reveal more choices) │
│  │
│ │
│ │
└──────────────────────────────────────────────────┘
@@ -0,0 +1,28 @@
---
source: src/question/order_select/tests.rs
assertion_line: 124
expression: backend

---
┌──────────────────────────────────────────────────┐
│ ? message (Press <space> to take and place an│
│ option) │
│❯ 0. 0 │
│ 1. 1 │
│ 2. 2 │
│ 3. 3 │
│ 4. 4 │
│ 5. 5 │
│ 6. 6 │
│ 7. 7 │
│ 8. 8 │
│ 9. 9 │
│ 10. 10 │
│ 11. 11 │
│ 12. 12 │
│ 13. 13 │
│(Move up and down to reveal more choices) │
│  │
│ │
│ │
└──────────────────────────────────────────────────┘
21 changes: 21 additions & 0 deletions examples/order-select.rs
@@ -0,0 +1,21 @@
use requestty::Question;

fn main() {
let order_select = Question::order_select("home_tasks")
.message("Please organize the tasks to be done at home")
.choices(vec![
"Make the bed",
"Clean the dishes",
"Mow the lawn",
])
.validate(|c, _| {
if c[0].text() == "Make the bed" {
Err("You have to make the bed first".to_string())
} else {
Ok(())
}
Lutetium-Vanadium marked this conversation as resolved.
Show resolved Hide resolved
})
.build();

println!("{:#?}", requestty::prompt_one(order_select));
}
21 changes: 20 additions & 1 deletion src/answer.rs
Expand Up @@ -5,6 +5,8 @@ use std::{
ops::{Deref, DerefMut},
};

use crate::question::OrderSelectItem;

/// The different answer types that can be returned by the [`Question`]s
///
/// [`Question`]: crate::question::Question
Expand Down Expand Up @@ -37,9 +39,10 @@ pub enum Answer {
///
/// [`confirm`]: crate::question::Question::confirm
Bool(bool),
/// ListItems will be returned by [`multi_select`].
/// ListItems will be returned by [`multi_select`] and [`order_select`].
///
/// [`multi_select`]: crate::question::Question::multi_select
/// [`multi_select`]: crate::question::Question::order_select
ListItems(Vec<ListItem>),
}

Expand Down Expand Up @@ -210,6 +213,16 @@ impl_from!(ExpandItem => ExpandItem);
impl_from!(ListItem => ListItem);
impl_from!(Vec<ListItem> => ListItems);

impl From<Vec<OrderSelectItem>> for Answer {
fn from(v: Vec<OrderSelectItem>) -> Self {
Answer::ListItems(
v.into_iter()
.map(|o| o.into())
.collect()
)
}
}

/// A representation of a [`Choice`] at a particular index.
///
/// It will be returned by [`select`] and [`raw_select`].
Expand All @@ -234,6 +247,12 @@ impl<I: Into<String>> From<(usize, I)> for ListItem {
}
}

impl AsRef<str> for ListItem {
fn as_ref(&self) -> &str {
&self.text
}
}

Lutetium-Vanadium marked this conversation as resolved.
Show resolved Hide resolved
/// A representation of a [`Choice`] for a particular key.
///
/// It will be returned by [`expand`].
Expand Down
2 changes: 1 addition & 1 deletion src/question/choice.rs
Expand Up @@ -31,7 +31,7 @@ impl<T: std::fmt::Debug> std::fmt::Debug for SelectList<T> {
}

impl<T> SelectList<T> {
fn new(f: fn(&T) -> bool) -> Self {
pub(crate) fn new(f: fn(&T) -> bool) -> Self {
Self {
choices: Vec::new(),
page_size: 15,
Expand Down