initial commit
This commit is contained in:
61
src/install_prompt.rs
Normal file
61
src/install_prompt.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::{fomod::GroupType, mod_config_installer::GroupPrompt};
|
||||
|
||||
pub fn prompt(p: GroupPrompt) -> Vec<usize> {
|
||||
println!("=== {} ===", p.name);
|
||||
println!();
|
||||
|
||||
for option in &p.options {
|
||||
println!(
|
||||
"[{}] {} ({:?}) => {}",
|
||||
option.idx + 1, option.name, option.option_type, option.description
|
||||
);
|
||||
}
|
||||
|
||||
let instruction = match p.select_type {
|
||||
GroupType::SelectExactlyOne => "Select one (enter number)",
|
||||
GroupType::SelectAtLeastOne => "Select one or more (e.g. 1 2 3)",
|
||||
GroupType::SelectAtMostOne => "Select one or none (enter number or 0 for none)",
|
||||
GroupType::SelectAny => "Select any (e.g. 1 2 3, or 0 for none)",
|
||||
GroupType::SelectAll => {
|
||||
println!(" (all options required)");
|
||||
return (0..p.options.len()).collect();
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
println!("=> {}", instruction);
|
||||
io::stdout().flush().unwrap();
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input).unwrap();
|
||||
input.trim().to_string();
|
||||
|
||||
let choices: Vec<usize> = input
|
||||
.split_whitespace()
|
||||
.filter_map(|s| s.parse::<usize>().ok())
|
||||
.filter(|&n| n > 0 && n <= p.options.len())
|
||||
.map(|n| n - 1)
|
||||
.collect();
|
||||
|
||||
let valid = match p.select_type {
|
||||
GroupType::SelectExactlyOne => {
|
||||
choices.len() == 1 // TODO: Check not usable
|
||||
}
|
||||
GroupType::SelectAtLeastOne => {
|
||||
!choices.is_empty() // TODO: Check not usable
|
||||
}
|
||||
GroupType::SelectAtMostOne => {
|
||||
choices.len() <= 1 // TODO: Check not usable
|
||||
}
|
||||
GroupType::SelectAny => true, // TODO: Check selected not usable,
|
||||
GroupType::SelectAll => unreachable!(),
|
||||
};
|
||||
|
||||
if valid {
|
||||
// TODO: Merge required plugins into final selection
|
||||
let final_selection = choices;
|
||||
return final_selection;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user