Table of Contents

Class FlowContext

Namespace
SharpConsoleUI.Flows
Assembly
SharpConsoleUI.dll

The imperative context handed to a flow body by Run<T>(ConsoleWindowSystem, Window?, Func<FlowContext, Task<T>>, IFlowHost?, CancellationToken). It exposes the flow's single cancellation Token plus verbs for presenting steps through the current IFlowHost: arbitrary typed content (Show<TResult>(IFlowStepContent<TResult>, string, FlowButtons)) and the built-in primitives (Confirm(string, string, string, string, NotificationSeverityEnum), Prompt(string, string, string?, NotificationSeverityEnum), RunWithProgress<TResult>(string, string, Func<CancellationToken, IProgress<string>, Task<TResult>>)). Each verb returns only the resolved value; a Cancel verdict (button or dismiss) maps to default/false/null.

public sealed class FlowContext
Inheritance
FlowContext
Inherited Members
Extension Methods

Properties

Committed

true once Commit() has been called for the current step. Marks a Back-barrier after side-effecting work so the wizard knows the step's effects must not be silently undone.

public bool Committed { get; }

Property Value

bool

StepCount

The total step count, used to render the step indicator (e.g. "step 2 of 4"). null for a flow with no fixed step count (the default for Tier A → no indicator shown).

public int? StepCount { get; }

Property Value

int?

StepIndex

The zero-based index of the current step, used to render the step indicator. Defaults to 0 for a Tier-A single-shot flow (no indicator shown). Set by the wizard loop (Tier B).

public int StepIndex { get; }

Property Value

int

Token

The single cancellation token for the whole flow. Esc / dismiss / host cancellation trips it.

public CancellationToken Token { get; }

Property Value

CancellationToken

Methods

Commit()

Marks the current step as committed (a Back-barrier). Call after performing side-effecting work so a subsequent Back is treated as crossing an irreversible boundary.

public void Commit()

Confirm(string, string, string, string, NotificationSeverityEnum)

Presents a built-in confirm dialog and returns the user's choice.

public Task<bool> Confirm(string title, string message, string ok = "OK", string cancel = "Cancel", NotificationSeverityEnum severity = NotificationSeverityEnum.Info)

Parameters

title string

The dialog title.

message string

The confirmation message.

ok string

Label for the affirmative button. Defaults to "OK".

cancel string

Label for the negative button. Defaults to "Cancel".

severity NotificationSeverityEnum

Severity controlling the dialog glyph and accent colour.

Returns

Task<bool>

true when confirmed; false on Cancel or dismiss.

Prompt(string, string, string?, NotificationSeverityEnum)

Presents a built-in single-line prompt and returns the entered text.

public Task<string?> Prompt(string title, string message, string? initial = null, NotificationSeverityEnum severity = NotificationSeverityEnum.Info)

Parameters

title string

The dialog title.

message string

The prompt question shown above the input.

initial string

Optional initial value pre-filled into the input.

severity NotificationSeverityEnum

Severity controlling the dialog glyph and accent colour.

Returns

Task<string>

The entered text, or null on Cancel or dismiss.

RunWithProgress<TResult>(string, string, Func<CancellationToken, IProgress<string>, Task<TResult>>)

Presents a built-in progress dialog while running work on a background thread, surfacing its IProgress<T> updates in a live status line.

public Task<TResult> RunWithProgress<TResult>(string title, string description, Func<CancellationToken, IProgress<string>, Task<TResult>> work)

Parameters

title string

The dialog title.

description string

The initial status text shown below the accent rule.

work Func<CancellationToken, IProgress<string>, Task<TResult>>

The async work; receives the flow's cancellation and a status reporter.

Returns

Task<TResult>

The work's result, or default when cancelled.

Type Parameters

TResult

The type produced by the work function.

Show<TResult>(IFlowStepContent<TResult>, string, FlowButtons)

Presents an arbitrary typed step body through the current host and returns its resolved value. Consistent with the other verbs (Confirm(string, string, string, string, NotificationSeverityEnum), Prompt(string, string, string?, NotificationSeverityEnum), RunWithProgress<TResult>(string, string, Func<CancellationToken, IProgress<string>, Task<TResult>>)), a Cancel verdict (Cancel button, dismiss, or token cancellation) is not an exception: this method simply returns default(TResult?) and does not abort the enclosing Run<T>(ConsoleWindowSystem, Window?, Func<FlowContext, Task<T>>, IFlowHost?, CancellationToken) body — the body decides how to react (return, branch, or propagate). Callers that need the precise verdict should present the step directly via PresentStep<TResult>(IFlowStepContent<TResult>, string, IReadOnlyList<FlowButton>, Func<IReadOnlyList<FlowButton>>) and inspect it.

public Task<TResult?> Show<TResult>(IFlowStepContent<TResult> content, string title = "", FlowButtons buttons = FlowButtons.OkCancel)

Parameters

content IFlowStepContent<TResult>

The step body to present.

title string

The title labelling the host frame.

buttons FlowButtons

The canonical button row to render. Defaults to OkCancel; pass None for content that builds and resolves its own buttons.

Returns

Task<TResult>

The content's value on a Next/Finish/OK verdict, or default(TResult?) on a Cancel verdict (button, dismiss, or token cancellation).

Type Parameters

TResult

The content's result type.