Skip to content

The progress bar displayed by WriteProgress() in the console becomes corrupted. #21293

Description

@yotsuda

Prerequisites

Steps to reproduce

If the StatusDescription includes Japanese characters, the progress bar becomes corrupted.
Execute the following cmdlet.

using System.Management.Automation;
namespace ReproProgress
{
    [Cmdlet(VerbsCommon.Get, "MyItem", SupportsShouldProcess = true)]
    public class MyCmdlet : Cmdlet
    {
        protected override void ProcessRecord()
        {
            string[] status = new string[] {
                "The first stage",
                "次の段階",
                "その次の段階",
                "そのまた次の段階",
                "もうすぐ終わるよ",
                "完了!"
            };

            var progress = new ProgressRecord(1, "My Status", "preparing...");

            int index = 0;
            foreach (var stage in status)
            {
                progress!.PercentComplete = (++index * 100) / status.Count();
                progress.StatusDescription = $"{index:D}/{status.Count()} {stage}";
                WriteProgress(progress);
                Thread.Sleep(500);
            }

            progress.RecordType = ProgressRecordType.Completed;
            WriteProgress(progress);
        }
    }
}

Expected behavior

The closing bracket at the end of the progress bar should be displayed on the same line without breaking to a new line.

Actual behavior

The closing bracket at the end of the progress bar appears on the next line and remains there even after the progress has completed.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

In progress:
image

The end bracket remains after completion:
image

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions