Skip to content

Commit f7d917f

Browse files
authored
Merge pull request #38 from ynqa/v0.5.1/dev
v0.5.1
2 parents 1eb3cd6 + 1f105b2 commit f7d917f

File tree

13 files changed

+56
-52
lines changed

13 files changed

+56
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Put the package in your `Cargo.toml`.
1111

1212
```toml
1313
[dependencies]
14-
promkit = "0.5.0"
14+
promkit = "0.5.1"
1515
```
1616

1717
## Features

promkit/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "promkit"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["ynqa <[email protected]>"]
55
edition = "2021"
66
description = "A toolkit for building your own interactive command-line tools"

promkit/src/core/checkbox.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, fmt, iter::FromIterator};
1+
use std::{collections::HashSet, fmt};
22

33
use crate::{core::listbox::Listbox, grapheme::StyledGraphemes};
44

@@ -16,20 +16,23 @@ pub struct Checkbox {
1616
picked: HashSet<usize>,
1717
}
1818

19-
impl<T: fmt::Display> FromIterator<T> for Checkbox {
20-
/// Creates a `Checkbox` from an iterator of items
21-
/// that implement the `Display` trait.
22-
/// Each item is added to the listbox,
23-
/// and the set of picked indices is initialized as empty.
24-
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
19+
impl Checkbox {
20+
/// Creates a new `Checkbox` from a vector of `fmt::Display`.
21+
pub fn from_displayable<E: fmt::Display, I: IntoIterator<Item = E>>(items: I) -> Self {
2522
Self {
26-
listbox: Listbox::from_iter(iter),
23+
listbox: Listbox::from_displayable(items),
24+
picked: HashSet::new(),
25+
}
26+
}
27+
28+
/// Creates a new `Checkbox` from a vector of `StyledGraphemes`.
29+
pub fn from_styled_graphemes(items: Vec<StyledGraphemes>) -> Self {
30+
Self {
31+
listbox: Listbox::from_styled_graphemes(items),
2732
picked: HashSet::new(),
2833
}
2934
}
30-
}
3135

32-
impl Checkbox {
3336
/// Creates a `Checkbox` from an iterator of tuples where the first element
3437
/// implements the `Display` trait and the second element is a bool indicating
3538
/// if the item is picked (selected).
@@ -61,7 +64,7 @@ impl Checkbox {
6164
.collect::<HashSet<usize>>();
6265

6366
Self {
64-
listbox: Listbox::from_iter(listbox_items),
67+
listbox: Listbox::from_displayable(listbox_items),
6568
picked: picked_indices,
6669
}
6770
}

promkit/src/core/listbox.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt, iter::FromIterator};
1+
use std::fmt;
22

33
use crate::{core::cursor::Cursor, grapheme::StyledGraphemes};
44

@@ -20,23 +20,24 @@ impl Default for Listbox {
2020
}
2121
}
2222

23-
impl<T: fmt::Display> FromIterator<T> for Listbox {
24-
/// Creates a `Listbox` from an iterator of items
25-
/// that implement the `Display` trait.
26-
/// Each item is converted to a `String`
27-
/// and collected into a `Vec<String>`.
28-
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
23+
impl Listbox {
24+
/// Creates a new `Listbox` from a vector of `fmt::Display`.
25+
pub fn from_displayable<E: fmt::Display, I: IntoIterator<Item = E>>(items: I) -> Self {
2926
Self(Cursor::new(
30-
iter.into_iter()
27+
items
28+
.into_iter()
3129
.map(|e| StyledGraphemes::from(format!("{}", e)))
3230
.collect(),
3331
0,
3432
false,
3533
))
3634
}
37-
}
3835

39-
impl Listbox {
36+
/// Creates a new `Listbox` from a vector of `StyledGraphemes`.
37+
pub fn from_styled_graphemes(items: Vec<StyledGraphemes>) -> Self {
38+
Self(Cursor::new(items, 0, false))
39+
}
40+
4041
/// Returns a reference to the vector of items in the listbox.
4142
pub fn items(&self) -> &Vec<StyledGraphemes> {
4243
self.0.contents()

promkit/src/core/text_editor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl TextEditor {
101101
let pos = self.position();
102102
self.0
103103
.contents_mut()
104-
.replace_range(pos..pos + 1, &ch.to_string());
104+
.replace_range(pos..pos + 1, ch.to_string());
105105
self.forward();
106106
}
107107
}

promkit/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
//!
1212
//! ```toml
1313
//! [dependencies]
14-
//! promkit = "0.5.0"
14+
//! promkit = "0.5.1"
1515
//! ```
1616
//!
1717
//! ## Features
1818
//!
1919
//! - Support cross-platform both UNIX and Windows owing to [crossterm](https://github.com/crossterm-rs/crossterm)
2020
//! - Various building methods
2121
//! - Preset; Support for quickly setting up a UI by providing simple parameters.
22-
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.5.0#readline)
23-
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.5.0#confirm)
24-
//! - [Password](https://github.com/ynqa/promkit/tree/v0.5.0#password)
25-
//! - [Select](https://github.com/ynqa/promkit/tree/v0.5.0#select)
26-
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.5.0#queryselect)
27-
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.5.0#checkbox)
28-
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.5.0#tree)
22+
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.5.1#readline)
23+
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.5.1#confirm)
24+
//! - [Password](https://github.com/ynqa/promkit/tree/v0.5.1#password)
25+
//! - [Select](https://github.com/ynqa/promkit/tree/v0.5.1#select)
26+
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.5.1#queryselect)
27+
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.5.1#checkbox)
28+
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.5.1#tree)
2929
//! - Combining various UI components.
3030
//! - They are provided with the same interface, allowing users to choose and
3131
//! assemble them according to their preferences.
@@ -39,7 +39,7 @@
3939
//!
4040
//! ## Examples/Demos
4141
//!
42-
//! See [here](https://github.com/ynqa/promkit/tree/v0.5.0#examplesdemos)
42+
//! See [here](https://github.com/ynqa/promkit/tree/v0.5.1#examplesdemos)
4343
//!
4444
//! ## Why *promkit*?
4545
//!

promkit/src/preset/checkbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Checkbox {
2929
/// # Arguments
3030
///
3131
/// * `items` - An iterator over items
32-
/// that implement the `Display` trait, to be used as options.
32+
/// that implement the `Display` trait, to be used as options.
3333
pub fn new<T: Display, I: IntoIterator<Item = T>>(items: I) -> Self {
3434
Self {
3535
title_state: text::State {
@@ -39,7 +39,7 @@ impl Checkbox {
3939
.build(),
4040
},
4141
checkbox_state: checkbox::State {
42-
checkbox: checkbox::Checkbox::from_iter(items),
42+
checkbox: checkbox::Checkbox::from_displayable(items),
4343
cursor: String::from("❯ "),
4444
active_mark: '☒',
4545
inactive_mark: '☐',

promkit/src/preset/listbox.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Listbox {
2828
/// # Arguments
2929
///
3030
/// * `items` - An iterator over items
31-
/// that implement the `Display` trait, to be used as options.
31+
/// that implement the `Display` trait, to be used as options.
3232
pub fn new<T: Display, I: IntoIterator<Item = T>>(items: I) -> Self {
3333
Self {
3434
title_state: text::State {
@@ -38,7 +38,7 @@ impl Listbox {
3838
.build(),
3939
},
4040
listbox_state: listbox::State {
41-
listbox: listbox::Listbox::from_iter(items),
41+
listbox: listbox::Listbox::from_displayable(items),
4242
cursor: String::from("❯ "),
4343
active_item_style: Some(StyleBuilder::new().fgc(Color::DarkCyan).build()),
4444
inactive_item_style: Some(StyleBuilder::new().build()),

promkit/src/preset/query_selector.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cell::RefCell, fmt::Display, iter::FromIterator};
1+
use std::{cell::RefCell, fmt::Display};
22

33
use crate::{
44
crossterm::style::{Attribute, Attributes, Color, ContentStyle},
@@ -37,10 +37,10 @@ impl QuerySelector {
3737
/// # Arguments
3838
///
3939
/// * `items` - An iterator over items that implement the `Display` trait,
40-
/// to be used as options in the list box.
40+
/// to be used as options in the list box.
4141
/// * `filter` - A function that takes the current input
42-
/// from the text editor and the list of items,
43-
/// returning a filtered list of items to display.
42+
/// from the text editor and the list of items,
43+
/// returning a filtered list of items to display.
4444
pub fn new<T, I>(items: I, filter: render::Filter) -> Self
4545
where
4646
T: Display,
@@ -66,7 +66,7 @@ impl QuerySelector {
6666
lines: Default::default(),
6767
},
6868
listbox_state: listbox::State {
69-
listbox: Listbox::from_iter(items),
69+
listbox: Listbox::from_displayable(items),
7070
cursor: String::from("❯ "),
7171
active_item_style: Some(StyleBuilder::new().fgc(Color::DarkCyan).build()),
7272
inactive_item_style: Some(StyleBuilder::new().build()),

promkit/src/preset/query_selector/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl crate::Renderer for Renderer {
7171
.map(|e| e.to_string())
7272
.collect(),
7373
);
74-
self.listbox_snapshot.after_mut().listbox = Listbox::from_iter(list);
74+
self.listbox_snapshot.after_mut().listbox = Listbox::from_displayable(list);
7575
}
7676
signal
7777
}

0 commit comments

Comments
 (0)