Skip to content

Commit

Permalink
Merge pull request #46 from ynqa/v0.6.1/dev
Browse files Browse the repository at this point in the history
v0.6.1
  • Loading branch information
ynqa authored Jan 6, 2025
2 parents 98f17d0 + 6a36881 commit 80ffd5b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Put the package in your `Cargo.toml`.

```toml
[dependencies]
promkit = "0.6.0"
promkit = "0.6.1"
```

## Features
Expand Down
2 changes: 1 addition & 1 deletion promkit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "promkit"
version = "0.6.0"
version = "0.6.1"
authors = ["ynqa <[email protected]>"]
edition = "2021"
description = "A toolkit for building your own interactive command-line tools"
Expand Down
12 changes: 12 additions & 0 deletions promkit/src/core/listbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ impl Listbox {
))
}

pub fn len(&self) -> usize {

Check warning on line 36 in promkit/src/core/listbox.rs

View workflow job for this annotation

GitHub Actions / test

struct `Listbox` has a public `len` method, but no `is_empty` method

Check warning on line 36 in promkit/src/core/listbox.rs

View workflow job for this annotation

GitHub Actions / test

struct `Listbox` has a public `len` method, but no `is_empty` method
self.0.contents().len()
}

pub fn push_string(&mut self, item: String) {
self.0.contents_mut().push(StyledGraphemes::from(item));
}

/// Creates a new `Listbox` from a vector of `StyledGraphemes`.
pub fn from_styled_graphemes(items: Vec<StyledGraphemes>) -> Self {
Self(Cursor::new(items, 0, false))
Expand Down Expand Up @@ -79,4 +87,8 @@ impl Listbox {
pub fn move_to_tail(&mut self) {
self.0.move_to_tail()
}

pub fn is_tail(&self) -> bool {
self.0.is_tail()
}
}
59 changes: 35 additions & 24 deletions promkit/src/jsonz.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashSet;

use rayon::prelude::*;

pub mod format;
Expand Down Expand Up @@ -392,36 +390,49 @@ pub fn create_rows<'a, T: IntoIterator<Item = &'a serde_json::Value>>(iter: T) -
rows
}

fn collect_paths(value: &serde_json::Value, current_path: &str, paths: &mut HashSet<String>) {
paths.insert(current_path.to_string());
#[derive(Debug)]
pub struct PathIterator<'a> {
stack: Vec<(String, &'a serde_json::Value)>,
}

match value {
serde_json::Value::Object(obj) => {
for (key, val) in obj {
let new_path = if current_path == "." {
format!(".{}", key)
} else {
format!("{}.{}", current_path, key)
};
collect_paths(val, &new_path, paths);
}
}
serde_json::Value::Array(arr) => {
for (i, val) in arr.iter().enumerate() {
let new_path = format!("{}[{}]", current_path, i);
collect_paths(val, &new_path, paths);
impl<'a> Iterator for PathIterator<'a> {

Check warning on line 398 in promkit/src/jsonz.rs

View workflow job for this annotation

GitHub Actions / test

the following explicit lifetimes could be elided: 'a

Check warning on line 398 in promkit/src/jsonz.rs

View workflow job for this annotation

GitHub Actions / test

the following explicit lifetimes could be elided: 'a
type Item = String;

fn next(&mut self) -> Option<Self::Item> {
if let Some((current_path, value)) = self.stack.pop() {
match value {
serde_json::Value::Object(obj) => {
for (key, val) in obj.iter() {
let new_path = if current_path == "." {
format!(".{}", key)
} else {
format!("{}.{}", current_path, key)
};
self.stack.push((new_path, val));
}
}
serde_json::Value::Array(arr) => {
for (i, val) in arr.iter().enumerate() {
let new_path = format!("{}[{}]", current_path, i);
self.stack.push((new_path, val));
}
}
_ => {}
}

Some(current_path)
} else {
None
}
_ => {}
}
}

pub fn get_all_paths<'a, T: IntoIterator<Item = &'a serde_json::Value>>(
iter: T,
) -> HashSet<String> {
let mut paths = HashSet::new();
) -> impl Iterator<Item = String> + 'a {
let mut stack = Vec::new();
for value in iter {
collect_paths(value, ".", &mut paths);
stack.push((".".to_string(), value));
}
paths
PathIterator { stack }
}
18 changes: 9 additions & 9 deletions promkit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
//!
//! ```toml
//! [dependencies]
//! promkit = "0.6.0"
//! promkit = "0.6.1"
//! ```
//!
//! ## Features
//!
//! - Support cross-platform both UNIX and Windows owing to [crossterm](https://github.com/crossterm-rs/crossterm)
//! - Various building methods
//! - Preset; Support for quickly setting up a UI by providing simple parameters.
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.6.0#readline)
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.6.0#confirm)
//! - [Password](https://github.com/ynqa/promkit/tree/v0.6.0#password)
//! - [Select](https://github.com/ynqa/promkit/tree/v0.6.0#select)
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.6.0#queryselect)
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.6.0#checkbox)
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.6.0#tree)
//! - [Readline](https://github.com/ynqa/promkit/tree/v0.6.1#readline)
//! - [Confirm](https://github.com/ynqa/promkit/tree/v0.6.1#confirm)
//! - [Password](https://github.com/ynqa/promkit/tree/v0.6.1#password)
//! - [Select](https://github.com/ynqa/promkit/tree/v0.6.1#select)
//! - [QuerySelect](https://github.com/ynqa/promkit/tree/v0.6.1#queryselect)
//! - [Checkbox](https://github.com/ynqa/promkit/tree/v0.6.1#checkbox)
//! - [Tree](https://github.com/ynqa/promkit/tree/v0.6.1#tree)
//! - Combining various UI components.
//! - They are provided with the same interface, allowing users to choose and
//! assemble them according to their preferences.
Expand All @@ -39,7 +39,7 @@
//!
//! ## Examples/Demos
//!
//! See [here](https://github.com/ynqa/promkit/tree/v0.6.0#examplesdemos)
//! See [here](https://github.com/ynqa/promkit/tree/v0.6.1#examplesdemos)
//!
//! ## Why *promkit*?
//!
Expand Down
4 changes: 2 additions & 2 deletions promkit/tests/jsonz_get_all_paths_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod get_all_paths {
)
.unwrap();

let actual = jsonz::get_all_paths([&v]);
let actual = jsonz::get_all_paths([&v]).collect::<HashSet<_>>();
let expected = HashSet::from_iter(
[
".",
Expand Down Expand Up @@ -114,7 +114,7 @@ mod get_all_paths {
.filter_map(serde_json::Result::ok)
.collect::<Vec<_>>();

let actual = jsonz::get_all_paths(binding.iter());
let actual = jsonz::get_all_paths(binding.iter()).collect::<HashSet<_>>();
let expected = HashSet::from_iter(
[
".",
Expand Down

0 comments on commit 80ffd5b

Please sign in to comment.