Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Sets the style of the spinner.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="style">The style.</param>
        /// <returns>The same instance so that multiple calls can be chained.</returns>
        public static SpinnerColumn Style(this SpinnerColumn column, Style?style)
        {
            if (column is null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            column.Style = style;
            return(column);
        }
Beispiel #3
0
        /// <summary>
        /// Sets the text that should be shown instead of the spinner
        /// once a task completes.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <param name="text">The text.</param>
        /// <returns>The same instance so that multiple calls can be chained.</returns>
        public static SpinnerColumn CompletedText(this SpinnerColumn column, string?text)
        {
            if (column is null)
            {
                throw new ArgumentNullException(nameof(column));
            }

            column.CompletedText = text;
            return(column);
        }