ynqa / promkit Goto Github PK
View Code? Open in Web Editor NEWA toolkit for building interactive prompt in Rust
License: MIT License
A toolkit for building interactive prompt in Rust
License: MIT License
Hi,
I'm trying to run the second example (the first one works), and I receive the following compilation error:
error[E0432]: unresolved import `promkit::selectbox`
--> src/main.rs:6:55
|
6 | build::Builder, crossterm::style, Result, select, selectbox::SelectBox
| ^^^^^^^^^ could not find `selectbox` in `promkit`
I'm working on version 0.1.1 on rust 1.62
I would like to easily annotate a configuration struct, to ask the user for input for various fields and give a hint on validation:
use derive_bla::AskUser;
#[derive(Debug, AskUser)]
struct MyConf {
#[ask(q="Please enter password:", hide_input=true, min_len=12)]
password: Option<String>,
#[ask(q="Please enter username:", min_len=3)]
username: Option<String>,
#[ask(q="Please enter age:", range=18..=85)]
age: Option<u8>,
}
fn main() -> Result<()> {
let mut conf = MyConf::default()
conf.password()?.validate()?;
conf.username()?.validate()?;
conf.age()?.validate()?;
println!("{conf#?}");
}
I would be interested if something like this is already existing, e.g. based on inquire, promkit, or if there is any interest to add this?
There are some ideas already in inquire
, but it feels a bit out of scope.
CC: mikaelmello/inquire#212
CC: mikaelmello/inquire#65
EDIT: It would basically be the clap
way of doing interactive prompts. Annotate something and give it to the user to let it be filled out. I think it comes with its own advantages and disadvantages, and excels a lot in a workflow where you suddenly want the user to fill out some data you already have bundled in a struct.
I think it could be a game changing feature, though. Because it would make dealing with interactive prompts much easier for a lot of users. Also, it would be excellent to have for people that don't want the full-fledged control of a ratatui
TUI, but still a bit more ergonomic when it comes to interactivity and developer experience creating such.
Nice project! I would love to use it (it looks stunning!). However for my use case I want to run the checkbox prompt with some items pre-selected. I think this is common enough to fit the checkbox preset.
existing work:
dialoguer has MultiSelect::items_checked.
Right now the filter functions gets the stringified items as an argument. Would it be possible to receive the items slice instead? It would make filtering in my case easier, since my data is structured.
Since type Validator<T> = fn(&T) -> bool;
, i can't do something like:
let existing_filenames = read_dir(...);
Readline::default()
.title("Name new file:")
.validator(|name| !existing_filenames.contains(name.to_string()), |name| format!("File {} already exists", name))
.prompt()?
.run()?;
Suggest swapping this to something like type Validator<T> = Box<dyn Fn(&T) -> bool>;
Thank you for making this library, it looks very nice!
Unfortunately, fake_input
uses os::unix
, preventing compilation on Windows.
I don't know if what fake_input
does is possible in a cross-platform fashion, but since it appears to be a utility for testing, and not essential to the library itself, maybe the module could, for now, be omitted on Windows via cfg
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.