/// <summary> /// Starts a new status display. /// </summary> /// <param name="status">The status to display.</param> /// <param name="action">he action to execute.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task StartAsync(string status, Func <StatusContext, Task> action) { // Set the progress columns var spinnerColumn = new SpinnerColumn(Spinner ?? Spinner.Known.Default) { Style = SpinnerStyle ?? Style.Plain, }; var progress = new Progress(_console) { FallbackRenderer = new StatusFallbackRenderer(), AutoClear = true, AutoRefresh = AutoRefresh, }; progress.Columns(new ProgressColumn[] { spinnerColumn, new TaskDescriptionColumn(), }); await progress.StartAsync(async ctx => { var statusContext = new StatusContext(ctx, ctx.AddTask(status), spinnerColumn); await action(statusContext).ConfigureAwait(false); }).ConfigureAwait(false); }
/// <summary> /// Sets the spinner style. /// </summary> /// <param name="context">The status context.</param> /// <param name="style">The spinner style.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static StatusContext SpinnerStyle(this StatusContext context, Style?style) { if (context is null) { throw new ArgumentNullException(nameof(context)); } context.SpinnerStyle = style; return(context); }
/// <summary> /// Sets the spinner. /// </summary> /// <param name="context">The status context.</param> /// <param name="spinner">The spinner.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static StatusContext Spinner(this StatusContext context, Spinner spinner) { if (context is null) { throw new ArgumentNullException(nameof(context)); } context.Spinner = spinner; return(context); }
/// <summary> /// Sets the status message. /// </summary> /// <param name="context">The status context.</param> /// <param name="status">The status message.</param> /// <returns>The same instance so that multiple calls can be chained.</returns> public static StatusContext Status(this StatusContext context, string status) { if (context is null) { throw new ArgumentNullException(nameof(context)); } context.Status = status; return(context); }