Skip to content

Bug: AnsiConsole.WriteLine output is not visible when ProgressTask display exceeds terminal height #1935

@fiso64

Description

@fiso64

Information

  • OS: Windows 10 LTSC
  • Version: 0.53.0
  • Terminal: Windows Terminal

Describe the bug
When using AnsiConsole.Progress to display a number of tasks that exceeds the terminal's height, status messages logged with AnsiConsole.WriteLine are not visible. The messages are correctly printed above the live progress display area, but because the progress display itself is taller than the viewport, the messages are immediately pushed off-screen. This makes it impossible to provide real-time log updates to the user during the operation.

To Reproduce
Minimal example:

using Spectre.Console;

public class Program
{
    private const int TOTAL_TASKS = 200;
    private const int CONCURRENCY_LIMIT = 2;

    private static int _completedTasks = 0;

    public static async Task Main(string[] args)
    {
        var semaphore = new SemaphoreSlim(CONCURRENCY_LIMIT);

        await AnsiConsole.Progress()
            .StartAsync(async ctx =>
            {
                var processingTasks = new List<Task>();
                var progressTasks = new List<ProgressTask>();

                for (int i = 0; i < TOTAL_TASKS; i++) 
                {
                    await semaphore.WaitAsync();
                    
                    var progressTask = ctx.AddTask($"Waiting to process item #{i + 1}...");
                    progressTasks.Add(progressTask);

                    processingTasks.Add(Task.Run(async () =>
                    {
                        try
                        {
                            progressTask.Description = $"Processing {progressTask.Description.Split('#').Last()}";
                            while (!progressTask.IsFinished)
                            {
                                await Task.Delay(10);
                                progressTask.Increment(5);
                            }

                            int currentCompleted = Interlocked.Increment(ref _completedTasks);

                            if (currentCompleted % 10 == 0)
                            {
                                AnsiConsole.WriteLine($"Completed {currentCompleted} tasks of {TOTAL_TASKS}");
                            }
                        }
                        finally
                        {
                            semaphore.Release();
                        }
                    }));
                }

                await Task.WhenAll(processingTasks);
            });
    }
}

Observe that the Completed N tasks... messages are never visible after the progress bars fill the terminal height.

Expected behavior
The status messages logged via AnsiConsole.WriteLine (e.g., Completed 10 tasks of 200) should be visible to the user as they are generated.

Personally, I would prefer for these log messages to be printed at the bottom (just like the progress bars), and gradually moved up as new progress tasks are added. This would give enough time for users to read the messages.


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions