Table of Contents

Class FlowWizardBuilder<TState>

Namespace
SharpConsoleUI.Flows
Assembly
SharpConsoleUI.dll

Fluent builder for a declarative Wizard<TState>(). Steps are added in order and reduced to a single navigation loop. Two step forms coexist:

  1. Code-driven — a Func<T1, T2, TResult> that runs the step body (using the shared FlowContext and state) and returns a FlowVerdict directly.
  2. Content + standardized buttons — a content factory that returns IFlowStepContent<TResult> (typed as object?); the wizard renders the context-aware button row, presents the content, and maps the chosen button to a verdict, applying any per-step fluent overrides (FlowStepConfig<TState>).
public sealed class FlowWizardBuilder<TState> where TState : new()

Type Parameters

TState

The mutable wizard state type; default-constructed unless seeded.

Inheritance
FlowWizardBuilder<TState>
Inherited Members
Extension Methods

Remarks

The content+buttons form presents the content as IFlowStepContent<TResult> of object?: the wizard does not consume the content's typed value. Such steps are for side-effect navigation where the content writes its result into TState itself (e.g. a version picker writing s.Version), and the fluent callbacks read TState. This keeps the builder mono-generic over TState rather than per-step typed.

Methods

Run(ConsoleWindowSystem, Window?, IFlowHost?, CancellationToken)

Runs the wizard: presents each step in order through host (or a default ModalWindowHost), honouring Next/Back/Cancel/Finish/Stay, the Back commit-barrier, and the optional step indicator. A wholly-blocked Back (at step 0 or pinned by the commit barrier) re-presents the current step unchanged (Stay semantics) — the wizard and its state are preserved and the loop continues. Cancellation surfaces as Cancelled; any other exception is logged and surfaced as Faulted.

public Task<FlowResult<TState>> Run(ConsoleWindowSystem ws, Window? parent, IFlowHost? host = null, CancellationToken cancellationToken = default)

Parameters

ws ConsoleWindowSystem

The window system the wizard presents into.

parent Window

Optional parent window for the default modal host; ignored when host is supplied.

host IFlowHost

Optional presentation host. When null a ModalWindowHost is used.

cancellationToken CancellationToken

Optional external cancellation. When it is cancelled the wizard's own token trips (via a linked source), so the in-flight step resolves Cancel and the loop surfaces Cancelled. Used, for example, by FlowControl to cancel a running inline wizard when its control is removed from the visual tree mid-flow.

Returns

Task<FlowResult<TState>>

The wizard outcome carrying the final state on completion.

Seed(TState)

Sets the initial wizard state (otherwise a default-constructed instance is used).

public FlowWizardBuilder<TState> Seed(TState state)

Parameters

state TState

The seed state.

Returns

FlowWizardBuilder<TState>

This builder, for chaining.

Step(Func<FlowContext, TState, Task<FlowVerdict>>)

Adds a code-driven step: the body runs with the shared context and state and returns a FlowVerdict that drives the loop.

public FlowWizardBuilder<TState> Step(Func<FlowContext, TState, Task<FlowVerdict>> step)

Parameters

step Func<FlowContext, TState, Task<FlowVerdict>>

The step body returning a navigation verdict.

Returns

FlowWizardBuilder<TState>

This builder, for chaining.

Step(Func<TState, IFlowStepContent<object?>>)

Adds a content + standardized buttons step: the factory builds the step content (which writes its result into TState), and the wizard renders the context-aware button row, presents the content, and maps the chosen button to a verdict. Returns a FlowStepConfig<TState> sub-builder for fluent per-step overrides (.OnNext, .OnBack, .OnCancel, .CanGoNext, .NextLabel, .BackLabel); its members return the same sub-builder, and adding the next step continues from the parent wizard builder.

public FlowStepConfig<TState> Step(Func<TState, IFlowStepContent<object?>> contentFactory)

Parameters

contentFactory Func<TState, IFlowStepContent<object>>

Builds the step content for the current state. The content's typed value is ignored; callbacks read TState.

Returns

FlowStepConfig<TState>

A FlowStepConfig<TState> for fluent customization of this step.

WithSeamlessHost()

Opts this wizard into the seamless single-window host (SwapContentHost): every step is presented in ONE reused modal window whose content is swapped per step (no open/close flicker between steps), instead of the default fresh-modal-per-step ModalWindowHost. Ignored when an explicit host is passed to Run(ConsoleWindowSystem, Window?, IFlowHost?, CancellationToken).

public FlowWizardBuilder<TState> WithSeamlessHost()

Returns

FlowWizardBuilder<TState>

This builder, for chaining.

WithStepIndicator()

Enables the step indicator: each step's FlowChrome carries a (Index, Count) tuple so the host can render e.g. "(2/3)".

public FlowWizardBuilder<TState> WithStepIndicator()

Returns

FlowWizardBuilder<TState>

This builder, for chaining.

WithTitle(string)

Sets a default title used for content+buttons steps that do not override it. Code-driven steps title their own host frames via the FlowContext verbs.

public FlowWizardBuilder<TState> WithTitle(string title)

Parameters

title string

The default step title.

Returns

FlowWizardBuilder<TState>

This builder, for chaining.