Form
ConsoleMonster.Interactive
A form or wizard: fields on one or more pages, a review page with the equivalent command line, named presets and (opt-in) remembered choices. Show it on its own (Show) or open it from a menu item.
Inheritance
- object
- Form
Usage
Explore 56 API references to this type
This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.
Returned or exposed by 26
- Extension method Form.Command
- Extension method Form.CommandStyle
- Extension method Form.Description
- Extension method Form.Page
- Extension method Form.Pages
- Extension method Form.Preset
- Extension method Form.Presets
- Extension method Form.Review
- Extension method Form.StorageKey
- Extension method Form.SubmitText
- Extension method Form.Title
- Method Form.Page
- Method Form.Preset
- Method FormFluent.Command
- Method FormFluent.CommandStyle
- Method FormFluent.Description
- Method FormFluent.Page
- Method FormFluent.Pages
- Method FormFluent.Preset
- Method FormFluent.Presets
- Method FormFluent.Review
- Method FormFluent.StorageKey
- Method FormFluent.SubmitText
- Method FormFluent.Title
- Property MenuItem.Form
- Method Ui.Form
Accepted by parameters 30
- Extension method Form.Command
- Extension method Form.CommandStyle
- Extension method Form.Description
- Extension method Form.Page
- Extension method Form.Pages
- Extension method Form.Preset
- Extension method Form.Presets
- Extension method Form.Review
- Extension method Form.StorageKey
- Extension method Form.SubmitText
- Extension method Form.Title
- Method FormFluent.Command
- Method FormFluent.CommandStyle
- Method FormFluent.Description
- Method FormFluent.Page
- Method FormFluent.Pages
- Method FormFluent.Preset
- Method FormFluent.Presets
- Method FormFluent.Review
- Method FormFluent.StorageKey
- Method FormFluent.SubmitText
- Method FormFluent.Title
- Extension method MenuItem.Form
- Extension method MenuItem.Form
- Extension method MenuItem.Form
- Method MenuItemFluent.Form
- Method MenuItemFluent.Form
- Method MenuItemFluent.Form
- Method MenuPreset.Form
- Method Ui.Form
Constructors
Methods
public T Add<T>(T field) #Adds a field to the last page.
Type Parameters
- T
- The field type.
Parameters
- field T
- The field.
Returns
T The field.public void Apply(IDictionary<string, object?> values) #Applies values to the form, whether or not it is shown: each named field takes its value, the shown text of every field follows (text and number boxes included), fields that depend on a changed field are reset as if the user had changed it (unless a value is given for them), and choice fields whose options load from a changed field load again (a value given for such a field is chosen once its options arrive). Fields not named keep their values. Unknown names and values a field cannot take (an option it does not have) are ignored. Values applied before the form is shown win over remembered choices and a preset. Call it from a synchronous menu action or handler, before showing the form, or from any thread inside a menu app (an asynchronous action): a call from another thread is queued for the thread that shows the form and applied on its next tick.
Parameters
- values System.Collections.Generic.IDictionary<string, object?>
- Values by field name (ignoring case), as the fields take them: a string, a number, a bool, or a list for a multi-choice field.
Exceptions
InvalidOperationExceptionโ The form is shown on another thread by a view that cannot take calls from other threads.
public void Apply(FormValues values) #Applies the values of another run of the form (every field, shown or hidden); see Form.Apply.
Parameters
- values ConsoleMonster.Interactive.FormValues
- The values, for example FormResult.Values.
public IReadOnlyList<string> ApplyStored(IDictionary<string, object?> stored) #Applies stored values (a preset or remembered choices); returns the names that could not be applied yet.
Parameters
- stored System.Collections.Generic.IDictionary<string, object?>
- The values.
Returns
IReadOnlyList<string> Names whose options are not loaded yet (applied after loading).public string BuildCommand() #The command line equivalent to the current values.
Returns
string The command line.public FormValues GetValues() #The current values, with visibility evaluated.
public ChoiceField MultiSelect(string key, string? label = null, IEnumerable<Choice>? choices = null) #Adds a multi-choice field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
- choices System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>? = null
- The choices, or null when a loader provides them.
public NumberField Number(string key, string? label = null) #Adds a number field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
public FormPage Page(string title, string? description = null) #Adds a page.
Parameters
- title string
- The page title.
- description string? = null
- A sentence under it.
public Form Page(string title, Action<FormPage> configure) #Adds a page and configures it.
Parameters
- title string
- The page title.
- configure System.Action<ConsoleMonster.Interactive.FormPage>
- Adds the fields.
public PathField Path(string key, string? label = null) #Adds a path field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
public Form Preset(string name, IDictionary<string, object?> values, string? description = null) #Adds a built-in preset (see Form.Presets).
Parameters
- name string
- The name; a saved preset cannot take it.
- values System.Collections.Generic.IDictionary<string, object?>
- Field values by field name, as the fields take them (a list for a multi-choice field).
- description string? = null
- A sentence about it, or null.
public Form Preset(string name, Action<FormPreset> configure) #Adds a built-in preset and configures it (see Form.Presets): p => p.Value("Path", @"D:\Weekly").Description("...").
Parameters
- name string
- The name; a saved preset cannot take it.
- configure System.Action<ConsoleMonster.Interactive.FormPreset>
- Sets the preset's values, description and preview.
public SecretField Secret(string key, string? label = null) #Adds a secret field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
public ChoiceField Select(string key, string? label = null, IEnumerable<Choice>? choices = null) #Adds a single-choice field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
- choices System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>? = null
- The choices, or null when a loader provides them.
public FormResult Show(Action<FormOptions> configure, CancellationToken cancellationToken = default) #Shows this form with freshly configured options.
Parameters
- configure System.Action<ConsoleMonster.Interactive.FormOptions>
- Form settings.
- cancellationToken System.Threading.CancellationToken = default
- Cancellation.
public FormResult Show(FormOptions? options = null, CancellationToken cancellationToken = default) #Shows the form and waits for it to be submitted or cancelled.
Parameters
- options ConsoleMonster.Interactive.FormOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the form.
public Task<FormResult> ShowAsync(Action<FormOptions> configure, CancellationToken cancellationToken = default) #Shows this form asynchronously with freshly configured options.
Parameters
- configure System.Action<ConsoleMonster.Interactive.FormOptions>
- Form settings.
- cancellationToken System.Threading.CancellationToken = default
- Cancellation.
public Task<FormResult> ShowAsync(FormOptions? options = null, CancellationToken cancellationToken = default) #Shows the form on a worker thread.
Parameters
- options ConsoleMonster.Interactive.FormOptions? = null
- Options.
- cancellationToken System.Threading.CancellationToken = default
- Cancels the form.
public TextField Text(string key, string? label = null) #Adds a text field to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
public ToggleField Toggle(string key, string? label = null) #Adds a toggle to the last page.
Parameters
- key string
- The key.
- label string? = null
- The label.
public Dictionary<string, object?> ToStored() #The storable values (no secrets, only fields that are remembered).
Returns
Dictionary<string, object?> The values.Inherited Methods
Properties
public string? Command { get; set; } #The command the equivalent command line starts with (Install-Toolbox, toolbox install).
public CommandStyle CommandStyle { get; set; } #How the equivalent command line is written.
public bool Review { get; set; } #Whether a review page (summary, equivalent command, run) comes after the last page.
public string? SubmitText { get; set; } #The caption of the button that submits the form; null uses "Run".
public string? StorageKey { get; set; } #The key presets and remembered choices are stored under; null uses the title.
public IList<FormPreset> Presets { get; } #The presets the form comes with: listed before the presets people save, marked as built in, never overwritten or deleted, and applied the same way (by FormOptions.Preset or the menu's command palette). A saved preset whose name matches a built-in one (ignoring case) is hidden.
public IEnumerable<Field> Fields { get; } #Every field, page by page.
Extension Methods
public static Form Command(Form form, string? value) #Sets Form.Command: The command the equivalent command line starts with (Install-Toolbox, toolbox install).
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value string?
- The value.
Examples
// C# initializer or property // C# fluent
form.Command = value; Ui.Form().Command(value);public static Form CommandStyle(Form form, CommandStyle value) #Sets Form.CommandStyle: How the equivalent command line is written.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value ConsoleMonster.Interactive.CommandStyle
- The value.
Examples
// C# initializer or property // C# fluent
form.CommandStyle = value; Ui.Form().CommandStyle(value);public static Form Description(Form form, string? value) #Sets Form.Description: A sentence under the title.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value string?
- The value.
Examples
// C# initializer or property // C# fluent
form.Description = value; Ui.Form().Description(value);public static Form Page(Form form, FormPage item) #Adds an item to Form.Pages: The pages, in order.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- item ConsoleMonster.Interactive.FormPage
- The item.
public static Form Pages(Form form, IEnumerable<FormPage> items) #Adds items to Form.Pages: The pages, in order.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.FormPage>
- The items, in order.
public static Form Preset(Form form, FormPreset item) #Adds an item to Form.Presets: The presets the form comes with: listed before the presets people save, marked as built in, never overwritten or deleted, and applied the same way (by FormOptions.Preset or the menu's command palette). A saved preset whose name matches a built-in one (ignoring case) is hidden.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- item ConsoleMonster.Interactive.FormPreset
- The item.
public static Form Presets(Form form, IEnumerable<FormPreset> items) #Adds items to Form.Presets: The presets the form comes with: listed before the presets people save, marked as built in, never overwritten or deleted, and applied the same way (by FormOptions.Preset or the menu's command palette). A saved preset whose name matches a built-in one (ignoring case) is hidden.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.FormPreset>
- The items, in order.
public static Form Review(Form form, bool value = true) #Sets Form.Review: Whether a review page (summary, equivalent command, run) comes after the last page.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value bool = true
- The value; true when omitted.
Examples
// C# initializer or property // C# fluent
form.Review = value; Ui.Form().Review(value);public static Form StorageKey(Form form, string? value) #Sets Form.StorageKey: The key presets and remembered choices are stored under; null uses the title.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value string?
- The value.
Examples
// C# initializer or property // C# fluent
form.StorageKey = value; Ui.Form().StorageKey(value);public static Form SubmitText(Form form, string? value) #Sets Form.SubmitText: The caption of the button that submits the form; null uses "Run".
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value string?
- The value.
Examples
// C# initializer or property // C# fluent
form.SubmitText = value; Ui.Form().SubmitText(value);public static Form Title(Form form, string value) #Sets Form.Title: The title.
Parameters
- form ConsoleMonster.Interactive.Form
- The instance.
- value string
- The value.
Examples
// C# initializer or property // C# fluent
form.Title = value; Ui.Form().Title(value);