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
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
Token
The single cancellation token for the whole flow. Esc / dismiss / host cancellation trips it.
public CancellationToken Token { get; }
Property Value
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
titlestringThe dialog title.
messagestringThe confirmation message.
okstringLabel for the affirmative button. Defaults to
"OK".cancelstringLabel for the negative button. Defaults to
"Cancel".severityNotificationSeverityEnumSeverity controlling the dialog glyph and accent colour.
Returns
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
titlestringThe dialog title.
messagestringThe prompt question shown above the input.
initialstringOptional initial value pre-filled into the input.
severityNotificationSeverityEnumSeverity controlling the dialog glyph and accent colour.
Returns
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
titlestringThe dialog title.
descriptionstringThe initial status text shown below the accent rule.
workFunc<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
defaultwhen cancelled.
Type Parameters
TResultThe 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
contentIFlowStepContent<TResult>The step body to present.
titlestringThe title labelling the host frame.
buttonsFlowButtonsThe 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
TResultThe content's result type.