Function inquire::set_global_render_config
source · pub fn set_global_render_config(config: RenderConfig<'static>)
Expand description
Acquires a write lock to the global RenderConfig object and updates the inner value with the provided argument.
Examples found in repository?
examples/empty_render_config.rs (line 11)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn main() -> InquireResult<()> {
inquire::set_global_render_config(RenderConfig::empty());
let _date = DateSelect::new("Date:").prompt()?;
let _category = Select::new("Category:", get_categories()).prompt()?;
let _payee = Text::new("Payee:")
.with_validator(required!("This field is required"))
.with_autocomplete(&payee_suggestor)
.with_help_message("e.g. Music Store")
.with_page_size(5)
.prompt()?;
let amount: f64 = CustomType::new("Amount:")
.with_formatter(&|i: f64| format!("${i}"))
.with_error_message("Please type a valid number")
.with_help_message("Type the amount in US dollars using a decimal point as a separator")
.prompt()
.unwrap();
let _description = Text::new("Description:")
.with_help_message("Optional notes")
.prompt()?;
let mut accounts = get_accounts();
let accounts_mut = accounts.iter_mut().collect();
let account = Select::new("Account:", accounts_mut).prompt()?;
account.balance -= amount;
let _tags = MultiSelect::new("Tags:", get_tags()).prompt()?;
println!("Your transaction has been successfully recorded.");
println!("The balance of {account} is now $311.09");
Ok(())
}
More examples
examples/render_config.rs (line 11)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> InquireResult<()> {
inquire::set_global_render_config(get_render_config());
let _date = DateSelect::new("Date:").prompt()?;
let _category = Select::new("Category:", get_categories()).prompt()?;
let _payee = Text::new("Payee:")
.with_validator(required!("This field is required"))
.with_autocomplete(&payee_suggestor)
.with_help_message("e.g. Music Store")
.with_page_size(5)
.prompt()?;
let amount: f64 = CustomType::new("Amount:")
.with_formatter(&|i: f64| format!("${i}"))
.with_error_message("Please type a valid number")
.with_help_message("Type the amount in US dollars using a decimal point as a separator")
.prompt()
.unwrap();
let _description = Text::new("Description:")
.with_help_message("Optional notes")
.prompt()?;
let mut accounts = get_accounts();
let accounts_mut = accounts.iter_mut().collect();
let account = Select::new("Account:", accounts_mut).prompt()?;
account.balance -= amount;
let _tags = MultiSelect::new("Tags:", get_tags()).prompt()?;
println!("Your transaction has been successfully recorded.");
println!(
"The balance of {} is now ${:.2}",
account.name, account.balance
);
Ok(())
}