Skip to content
ConsoleMonster
Class

Form

ConsoleMonster.Interactive

Namespace
ConsoleMonster.Interactive
Assembly
ConsoleMonster
Modifiers
sealed

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

Accepted by parameters 30

Constructors

public Form(string title) #

Creates a form.

Parameters

title string required
The title.

Methods

public T Add<T>(T field) #

Adds a field to the last page.

Type Parameters

T
The field type.

Parameters

field T required
The field.

Returns

T The field.
Apply 2 overloads
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?> required
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 required
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?> required
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 Field? Find(string key) #

Finds a field by key.

Parameters

key string required
The key.

Returns

Field? The field, or null.
public FormValues GetValues() #

The current values, with visibility evaluated.

Returns

FormValues The values.
public ChoiceField MultiSelect(string key, string? label = null, IEnumerable<Choice>? choices = null) #

Adds a multi-choice field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.
choices System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>? = null optional
The choices, or null when a loader provides them.

Returns

ChoiceField The field.
public NumberField Number(string key, string? label = null) #

Adds a number field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.

Returns

NumberField The field.
Page 2 overloads
public FormPage Page(string title, string? description = null) #

Adds a page.

Parameters

title string required
The page title.
description string? = null optional
A sentence under it.

Returns

FormPage The page.
public Form Page(string title, Action<FormPage> configure) #

Adds a page and configures it.

Parameters

title string required
The page title.
configure System.Action<ConsoleMonster.Interactive.FormPage> required
Adds the fields.

Returns

Form The form.
public PathField Path(string key, string? label = null) #

Adds a path field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.

Returns

PathField The field.
Preset 2 overloads
public Form Preset(string name, IDictionary<string, object?> values, string? description = null) #

Adds a built-in preset (see Form.Presets).

Parameters

name string required
The name; a saved preset cannot take it.
values System.Collections.Generic.IDictionary<string, object?> required
Field values by field name, as the fields take them (a list for a multi-choice field).
description string? = null optional
A sentence about it, or null.

Returns

Form The form.
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 required
The name; a saved preset cannot take it.
configure System.Action<ConsoleMonster.Interactive.FormPreset> required
Sets the preset's values, description and preview.

Returns

Form The form.
public SecretField Secret(string key, string? label = null) #

Adds a secret field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.

Returns

SecretField The field.
public ChoiceField Select(string key, string? label = null, IEnumerable<Choice>? choices = null) #

Adds a single-choice field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.
choices System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.Choice>? = null optional
The choices, or null when a loader provides them.

Returns

ChoiceField The field.
Show 2 overloads
public FormResult Show(Action<FormOptions> configure, CancellationToken cancellationToken = default) #

Shows this form with freshly configured options.

Parameters

configure System.Action<ConsoleMonster.Interactive.FormOptions> required
Form settings.
cancellationToken System.Threading.CancellationToken = default optional
Cancellation.

Returns

FormResult The answers.
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 optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Cancels the form.

Returns

FormResult The result.
ShowAsync 2 overloads
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> required
Form settings.
cancellationToken System.Threading.CancellationToken = default optional
Cancellation.

Returns

Task<FormResult> The answers.
public Task<FormResult> ShowAsync(FormOptions? options = null, CancellationToken cancellationToken = default) #

Shows the form on a worker thread.

Parameters

options ConsoleMonster.Interactive.FormOptions? = null optional
Options.
cancellationToken System.Threading.CancellationToken = default optional
Cancels the form.

Returns

Task<FormResult> The result.
public TextField Text(string key, string? label = null) #

Adds a text field to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.

Returns

TextField The field.
public ToggleField Toggle(string key, string? label = null) #

Adds a toggle to the last page.

Parameters

key string required
The key.
label string? = null optional
The label.

Returns

ToggleField The field.
public Dictionary<string, object?> ToStored() #

The storable values (no secrets, only fields that are remembered).

Returns

Dictionary<string, object?> The values.

Properties

public string Title { get; set; } #

The title.

public string? Description { get; set; } #

A sentence under the title.

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 IList<FormPage> Pages { get; } #

The pages, in order.

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 required
The instance.
value string? required
The value.

Returns

Form The same instance.

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 required
The instance.
value ConsoleMonster.Interactive.CommandStyle required
The value.

Returns

Form The same instance.

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 required
The instance.
value string? required
The value.

Returns

Form The same instance.

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 required
The instance.
item ConsoleMonster.Interactive.FormPage required
The item.

Returns

Form The same instance.
public static Form Pages(Form form, IEnumerable<FormPage> items) #

Adds items to Form.Pages: The pages, in order.

Parameters

form ConsoleMonster.Interactive.Form required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.FormPage> required
The items, in order.

Returns

Form The same instance.
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 required
The instance.
item ConsoleMonster.Interactive.FormPreset required
The item.

Returns

Form The same instance.
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 required
The instance.
items System.Collections.Generic.IEnumerable<ConsoleMonster.Interactive.FormPreset> required
The items, in order.

Returns

Form The same instance.
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 required
The instance.
value bool = true optional
The value; true when omitted.

Returns

Form The same instance.

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 required
The instance.
value string? required
The value.

Returns

Form The same instance.

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 required
The instance.
value string? required
The value.

Returns

Form The same instance.

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 required
The instance.
value string required
The value.

Returns

Form The same instance.

Examples

// C# initializer or property    // C# fluent
form.Title = value;              Ui.Form().Title(value);