For example, Input::new()
is now InteractionEnvironment::new_input()
. This allows all interactions to re-use the new locale
field stored in the environment, and brings the API in line with how ProgressBar
already stored the environment internally.
7YOM2QEFZ5HWVEISP3VIR2GKF2NNH4KKTLTWEMYMMWNYKICXWTZAC
5P3O2D3G76VM3WSYDCVTOFFMGHLMK2K47K6UTR4P64R2GAM7X5JAC
KFFAQIZUWCJGRHOPDYXZNZM5DESD6XYU4PK3YH7T25OIMRR6O2MQC
RUCC2HKZZTUHN3G6IWS4NK3VYGXAI6PORJH2YZKPRAYSDWH63ESQC
UKFEFT6LSI4K7X6UHQFZYD52DILKXMZMYSO2UYS2FCHNPXIF4BEQC
JUV7C6ET4ZQJNLO7B4JB7XMLV2YUBZB4ARJHN4JEPHDGGBWGLEVAC
3BUFFCHQHO6GJ7NQ3274OZMMOWSGGUEQJWQWQHCTYYXGEGYQGFTAC
QJC4IQITOQP65AFLA5CMH2EXHB6B3SOLW2XBV72U5ZQU2KOR2EIAC
U2PHMYPDFQQYTPDVVJLWDJM5G45ILXLWDDDTZVV2NBOSCED323MQC
NEBSVXIASWSJO2CVU3VWRONIWJJDLL3VDS6WNKQBWQBRUUI7RSYAC
BAH2JCJPTDXAE6XGSLIPBQZU4GQY65HI66Q4XTFNL65MV6VSNF2QC
NB7K77TZAT5ESYFZATMSGYPKOW3GGVWZLLNDAD4JKZEG7KUAX2HAC
IXBE5Q6TIJTOYDJMGBQKIT6B45567KFV3CYW6PJII2ZLW7CXNEJAC
pub fn interact(
self,
environment: &InteractionEnvironment,
) -> Result<Option<usize>, InteractionError> {
match environment.context {
pub fn interact(self) -> Result<Option<usize>, InteractionError> {
match self.environment.context {
let confirmation_text = confirmation.localize();
let mismatch_error_text = mismatch_error.localize();
let confirmation_text = confirmation.message_for_locale(&self.environment.locale);
let mismatch_error_text = mismatch_error.message_for_locale(&self.environment.locale);
pub fn interact(
self,
environment: &InteractionEnvironment,
) -> Result<Option<String>, InteractionError> {
match environment.context {
pub fn interact(self) -> Result<Option<String>, InteractionError> {
match self.environment.context {
pub fn interact(
self,
environment: &InteractionEnvironment,
) -> Result<Option<String>, InteractionError> {
match environment.context {
pub fn interact(self) -> Result<Option<String>, InteractionError> {
match self.environment.context {
impl Confirm {
pub fn interact(
self,
environment: &InteractionEnvironment,
) -> Result<Option<bool>, InteractionError> {
match environment.context {
impl<'environment> Confirm<'environment> {
pub(crate) fn new_from_environment(environment: &'environment InteractionEnvironment) -> Self {
Self {
environment,
default: None,
prompt: None,
}
}
pub fn interact(self) -> Result<Option<bool>, InteractionError> {
match self.environment.context {
impl ProgressBar {
pub fn new(environment: &InteractionEnvironment, length: u64) -> Self {
let progress_bar =
indicatif::ProgressBar::new(length).with_style(PROGRESS_TEMPLATE.clone());
impl<'environment> ProgressBar {
pub(crate) fn new_from_environment<L: Localize>(
environment: &'environment InteractionEnvironment,
message: L,
length: u64,
) -> Self {
let localized_text = message.message_for_locale(&environment.locale);
let progress_bar = indicatif::ProgressBar::new(length)
.with_style(PROGRESS_TEMPLATE.clone())
.with_message(localized_text);
}
pub fn with_message<L: Localize>(mut self, message: L) -> Self {
let localized_text = message.localize();
self.progress_bar = self.progress_bar.with_message(localized_text);
self
self.progress_bars.println(message.localize())
self.progress_bars
.println(message.message_for_locale(&self.locale))
}
}
macro_rules! impl_constructor {
($prompt_name:ident, $prompt_type:ident) => {
impl InteractionEnvironment {
#[must_use]
pub fn $prompt_name<'environment>(&'environment self) -> $prompt_type<'environment> {
$prompt_type::new_from_environment(self)
}
}
};
}
// Create constructors on InteractionEnvironment for different interaction types
impl_constructor!(new_confirm, Confirm);
impl_constructor!(new_editor, Editor);
impl_constructor!(new_input, Input);
impl_constructor!(new_password, Password);
impl_constructor!(new_select, Select);
// Special implementation for progress bars as the signature is different
impl InteractionEnvironment {
pub fn new_progress<'environment, L: Localize>(
&'environment self,
message: L,
length: u64,
) -> ProgressBar {
ProgressBar::new_from_environment(self, message, length)
pub fn edit(
&self,
environment: &InteractionEnvironment,
text: &str,
) -> Result<Option<String>, InteractionError> {
match environment.context {
pub fn edit(self, text: &str) -> Result<Option<String>, InteractionError> {
match self.environment.context {