yggdrasil/src/util/input.rs

59 lines
2.0 KiB
Rust

/*
* Yggdrasil: Minecraft authentication server
* Copyright (C) 2023 0xf8.dev@proton.me
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use anyhow::Result;
use dialoguer::{MultiSelect, Password};
use dialoguer::theme::ColorfulTheme;
use super::structs::profile_attributes::ProfileAttributesSimple;
pub struct Input {}
impl Input {
pub async fn password() -> Result<String> {
let theme = ColorfulTheme::default();
let mut password = Password::with_theme(&theme);
password.with_prompt("Password");
Ok(password.interact()?)
}
pub async fn attributes() -> Result<ProfileAttributesSimple> {
let theme = ColorfulTheme::default();
let mut select = MultiSelect::with_theme(&theme);
select.with_prompt("Attributes");
select.items(&["Can chat", "Can play multiplayer", "Can play realms", "Use profanity filter"]);
select.defaults(&[true, true, true, false]);
let mut attr = ProfileAttributesSimple {
can_chat: false,
can_play_multiplayer: false,
can_play_realms: false,
use_filter: false,
};
for a in select.interact()? {
match a {
0 => attr.can_chat = true,
1 => attr.can_play_multiplayer = true,
2 => attr.can_play_realms = true,
3 => attr.use_filter = true,
_ => ()
}
}
Ok(attr)
}
}