1
0
Fork
You've already forked demand
0
  • Rust 100%
Vulpesx d7e32467b7
feat: list ( #51 )
* feat: input suggestions are now a slice
chore: update examples
* refactor: SpinnerActions doesnt need to be exported, that was from an earlier version of run actions
* fix: typo
* feat: allow non static str
* feat: SpinnerActionRunner.title now accepts into<string>
* fix: input not showing cursor when done
* fix: clippy warnings
* feat: fancy list
chore: test
chore: examples
2024年05月10日 16:19:20 -05:00
.github feat: add tests to verify initial rendering ( #25 ) 2024年01月23日 20:39:08 +01:00
assets chore: update example gifs 2024年02月22日 14:55:07 -03:00
examples feat: list ( #51 ) 2024年05月10日 16:19:20 -05:00
src feat: list ( #51 ) 2024年05月10日 16:19:20 -05:00
.gitignore init 2023年12月21日 04:22:58 -06:00
.mise.toml added cargo-release config 2024年01月24日 19:53:13 -06:00
Cargo.toml chore: Release demand version 1.1.2 2024年04月27日 10:00:11 +02:00
CHANGELOG.md chore: Release demand version 1.1.2 2024年04月27日 10:00:11 +02:00
cliff.toml chore: add changelog via git-cliff ( #29 ) 2024年01月25日 00:54:57 +01:00
LICENSE init 2023年12月21日 04:22:58 -06:00
README.md chore: remove unnecessary println statements from examples 2024年02月22日 14:37:40 -03:00

demand

Crates.io docs.rs GitHub License GitHub Workflow Status GitHub issues

A prompt library for Rust. Based on huh? for Go. Maintained by @jdx and @roele.

Input

  • Single-line text input with variable prompt and placeholder
  • Auto-complete suggestions with TAB
  • Validate input with a custom closure

Run example with cargo run --example input.

Input

usedemand::Input;fn main(){letnotempty_minlen=|s: &str|{ifs.is_empty(){returnErr("Name cannot be empty");}ifs.len()<8{returnErr("Name must be at least 8 characters");}Ok(())};lett=Input::new("What's your name?").description("We'll use this to personalize your experience.").placeholder("Enter your name").prompt("Name: ").suggestions(vec!["Adam Grant","Danielle Steel","Eveline Widmer-Schlumpf","Robert De Niro","Ronaldo Rodrigues de Jesus","Sarah Michelle Gellar","Yael Naim","Zack Snyder",]).validation(notempty_minlen);leti=t.run().expect("error running input");}

Password

Run example with cargo run --example input-password.

Input

usedemand::Input;fn main(){lett=Input::new("Set a password").placeholder("Enter password").prompt("Password: ").password(true);leti=t.run().expect("error running input");}

Select

Select from a list of options.

Run example with cargo run --example select.

Select

usedemand::{DemandOption,Select};fn main(){letms=Select::new("Toppings").description("Select your topping").filterable(true).option(DemandOption::new("Lettuce")).option(DemandOption::new("Tomatoes")).option(DemandOption::new("Charm Sauce")).option(DemandOption::new("Jalapenos").label("Jalapeños")).option(DemandOption::new("Cheese")).option(DemandOption::new("Vegan Cheese")).option(DemandOption::new("Nutella"));ms.run().expect("error running select");}

Multiselect

Select multiple options from a list. Run example with cargo run --example multiselect.

Multiselect

usedemand::{DemandOption,MultiSelect};fn main(){letms=MultiSelect::new("Toppings").description("Select your toppings").min(1).max(4).filterable(true).option(DemandOption::new("Lettuce").selected(true)).option(DemandOption::new("Tomatoes").selected(true)).option(DemandOption::new("Charm Sauce")).option(DemandOption::new("Jalapenos").label("Jalapeños")).option(DemandOption::new("Cheese")).option(DemandOption::new("Vegan Cheese")).option(DemandOption::new("Nutella"));ms.run().expect("error running multi select");}

Confirm

Confirm a question with a yes or no. Run example with cargo run --example confirm.

Confirm

usedemand::Confirm;fn main(){letms=Confirm::new("Are you sure?").affirmative("Yes!").negative("No.");letyes=ms.run().expect("error running confirm");}

Spinner

Spinners are used to indicate that a process is running. Run example with cargo run --example spinner.

Spinner

usestd::{thread::sleep,time::Duration};usedemand::{Spinner,SpinnerStyle};fn main(){Spinner::new("Loading Data...").style(SpinnerStyle::line()).run(||{sleep(Duration::from_secs(2));}).expect("error running spinner");}

Themes

Supply your own custom theme or choose from one of the predefined themes:

Derive a custom theme from the default theme.

lettheme=Theme{selected_prefix: String::from(" •"),selected_prefix_fg: Theme::color_rgb(2,191,135),unselected_prefix: String::from(" "),..Theme::default()};Input::new("What's your e-mail?").description("Please enter your e-mail address.").placeholder("name@domain.com").theme(&theme).run().expect("error running input")?;

Base 16

base16

Charm

Default if colors are enabled in the console.

charm

Catppuccin

catppuccin

Dracula

dracula

New

Default if colors are NOT enabled in the console.

new

"demand"

The name of this library is inspired by a great mistranslation that soured US-French relations in 1830. In French, the verb "demander" means "to ask".