Crates.io | promptio |
lib.rs | promptio |
version | 0.1.0 |
source | src |
created_at | 2022-05-01 04:55:18.643825 |
updated_at | 2022-05-01 04:55:18.643825 |
description | A toolkit for building your own interactive command-line tools |
homepage | |
repository | https://github.com/ynqa/promptio |
max_upload_size | |
id | 578474 |
size | 85,488 |
A toolkit for building your own interactive command-line tools in Rust, utilizing crossterm.
Put the package in your Cargo.toml
.
[dependencies]
promptio = "0.1.0"
Readline:
use promptio::{build::Builder, readline, Result};
fn main() -> Result<()> {
let mut p = readline::Builder::default().build()?;
loop {
let (line, exit_code) = p.run()?;
if exit_code == 0 {
println!("result: {:?}", line);
} else {
return Ok(());
}
}
}
Select:
use crossterm::style;
use promptio::{
build::Builder,
edit::{Register, SelectBox},
select, Result,
};
fn main() -> Result<()> {
let mut selectbox = Box::new(SelectBox::default());
selectbox.register_all((0..100).map(|v| v.to_string()).collect::<Vec<String>>());
let mut p = select::Builder::default()
.title("Q: What number do you like?")
.title_color(style::Color::DarkGreen)
.selectbox(selectbox)
.build()?;
let (line, exit_code) = p.run()?;
if exit_code == 0 {
println!("result: {:?}", line)
}
Ok(())
}