Struct inquire::ui::RenderConfig

source ·
pub struct RenderConfig {
Show 20 fields pub prompt_prefix: Styled<&'static str>, pub answered_prompt_prefix: Styled<&'static str>, pub prompt: StyleSheet, pub default_value: StyleSheet, pub placeholder: StyleSheet, pub help_message: StyleSheet, pub password_mask: char, pub text_input: StyleSheet, pub answer: StyleSheet, pub canceled_prompt_indicator: Styled<&'static str>, pub error_message: ErrorMessageRenderConfig, pub highlighted_option_prefix: Styled<&'static str>, pub scroll_up_prefix: Styled<&'static str>, pub scroll_down_prefix: Styled<&'static str>, pub selected_checkbox: Styled<&'static str>, pub unselected_checkbox: Styled<&'static str>, pub option_index_prefix: IndexPrefix, pub option: StyleSheet, pub calendar: CalendarRenderConfig, pub editor_prompt: StyleSheet,
}
Expand description

Rendering configuration that can be applied to a prompt.

Render configurations can set mostly style sheets for particular parts of the prompt layout. Additionally, it allows you to set the content of a few tokens, such as prompt or error message prefixes.

Example

use inquire::ui::{Color, RenderConfig, Styled};

let empty: RenderConfig = RenderConfig::empty();
let default: RenderConfig = RenderConfig::default();

let prompt_prefix = Styled::new("$").with_fg(Color::DarkRed);
let mine = default.with_prompt_prefix(prompt_prefix);

Fields§

§prompt_prefix: Styled<&'static str>

Prefix added before prompts.

Note: a space character will be added to separate the prefix and the prompt message.

§answered_prompt_prefix: Styled<&'static str>

Prefix added before answered prompts.

Note: a space character will be added to separate the prefix and the prompt message.

§prompt: StyleSheet

Style of the prompt message, applicable to all prompt types.

§default_value: StyleSheet

Render configuration of default values.

Note: default values are displayed wrapped in parenthesis, e.g. (yes). Non-styled space characters is added before the default value display and after the default value, as separators.

§placeholder: StyleSheet

Render configuration of placeholders.

Note: placeholders are displayed wrapped in parenthesis, e.g. (yes). Non-styled space characters is added before the default value display and after the default value, as separators.

§help_message: StyleSheet

Render configuration of help messages.

Note: help messages are displayed wrapped in brackets, e.g. [Be careful!].

§password_mask: char

Character used to mask password text inputs when in mode Masked.

Note: Styles for masked text inputs are set in the text_input configuration.

§text_input: StyleSheet

Style sheet for text inputs.

Note: a non-styled space character is added before the text input as a separator from the prompt message (or default value display).

§answer: StyleSheet

Render configuration of final prompt answers (submissions).

Note: a non-styled space character is added before the answer as a separator from the prompt message (or default value display).

§canceled_prompt_indicator: Styled<&'static str>

Render configuration of the message printed in the place of an answer when the prompt is canceled by the user - by pressing ESC.

Note: a non-styled space character is added before the indicator as a separator from the prompt message.

§error_message: ErrorMessageRenderConfig

Render configuration for error messages.

§highlighted_option_prefix: Styled<&'static str>

Prefix for the current highlighted option.

Note: a space character will be added to separate the prefix and the option value or the checkbox.

§scroll_up_prefix: Styled<&'static str>

Prefix for the option listed at the top of the page, when it is possible to scroll up.

Note: a space character will be added to separate the prefix and the option value or the checkbox.

§scroll_down_prefix: Styled<&'static str>

Prefix for the option listed at the bottom of the page, when it is possible to scroll down.

Note: a space character will be added to separate the prefix and the option value or the checkbox.

§selected_checkbox: Styled<&'static str>

Selected checkbox in multi-select options.

Note: a space character will be added to separate the checkbox from a possible prefix, and to separate the checkbox from the option value to the right.

§unselected_checkbox: Styled<&'static str>

Unselected checkbox in multi-select options.

Note: a space character will be added to separate the checkbox from a possible prefix, and to separate the checkbox from the option value to the right.

§option_index_prefix: IndexPrefix

Definition of index prefixes in option lists.

§option: StyleSheet

Style sheet for options.

Note: a non-styled space character is added before the option value as a separator from the prefix.

§calendar: CalendarRenderConfig

Render configuration for calendar Render configuration for date prompts.

§editor_prompt: StyleSheet

Style sheet of the hint in editor prompts.

The hint is formatted as [(e) to open {}, (enter) to submit] with the editor name.

Implementations§

RenderConfig in which no colors or attributes are applied.

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 {} is now $311.09", account);

    Ok(())
}

RenderConfig where default colors and attributes are applied.

Sets the prompt prefix and its style sheet.

Sets style for text inputs.

Sets the style sheet for default values.

Sets the style sheet for help messages.

Sets the style sheet for answers.

Sets the render configuration for error messages.

Sets the styled component for prefixes in highlighted options.

Sets the styled component for prefixes in scroll-up indicators.

Sets the styled component for prefixes in scroll-down indicators.

Sets the styled component for selected checkboxes.

Sets the styled component for unselected checkboxes.

Sets the index prefix for option lists.

Sets the style sheet for option values.

Sets the indicator for canceled prompts.

Examples found in repository?
examples/editor.rs (line 31)
29
30
31
32
fn description_render_config() -> RenderConfig {
    RenderConfig::default()
        .with_canceled_prompt_indicator(Styled::new("<skipped>").with_fg(Color::DarkYellow))
}

Sets the render configuration for calendars.

Sets the render configuration for editor prompts.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.