question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integrated Console - Write-Progress messes things up

See original GitHub issue

Issue Description

Running a script with Write-Progress screws up the console.

Example Script

function MyAwesomeScript {

	[CmdletBinding()]
	param (
		[Parameter()]
		[string]
		$Name
	)

	$WelcomeMessage = @();

	for ($i = 0; $i -lt 50; $i++) {
		Write-Progress -Activity "Getting ready to greet you!" -PercentComplete ($i/50*100)
		$WelcomeMessage += "Hello $Name"
	}

	$WelcomeMessage
}

MyAwesomeScript -Name Micah

Expected Behaviour

Should look like this (example taken from pwsh running in VSCode):

image

Actual Behaviour

Looks like this:

image

The prompt is getting rendered towards the top instead of at the end of the content

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
andschwacommented, Feb 18, 2022
Screen Shot 2022-02-18 at 10 47 41 AM
2reactions
SeeminglySciencecommented, Nov 10, 2021

A couple of things missing from the old host implementation:

https://github.com/PowerShell/PowerShellEditorServices/blob/6b1e77d6223ff61c4af3cbeedf687e1f65f3ac18/src/PowerShellEditorServices/Services/PowerShellContext/Session/Host/EditorServicesPSHostUserInterface.cs#L609-L622

Track current progress messages so they can be cleared up when a the top level pipeline completes. Also a little bit under that it’s hooking into an execution status event to call ClearProgress after pipeline completion.


Since it’s not very obvious why you’d need to do that, I’ll copy and paste an explanation from when I was suggesting it as the fix:

I still think the best bet is to reuse the existing ConsoleHost. I tested it, it does work. The problem is that since ConsoleHost isn’t the one creating pipelines, it isn’t cleaning up progress messages after each pipeline invocation. There’s a few options

  1. Keep track of the progress messages we send to ConsoleHost and send clean up progress messages for any that the user did not. This would be my suggestion (assuming it works)

(it does)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Console output overhead: why is writing to stdout so slow?
In this case, tqdm will output progress asynchronously according to the Notebook API. tqdm outputting inside Jupyter Notebook / VS Code Python ...
Read more >
Write-Progress (Microsoft.PowerShell.Utility) - Microsoft Learn
The Write-Progress cmdlet displays a progress bar in a PowerShell command window that depicts the status of a running command or script.
Read more >
How to make a progress bar in C# Console - YouTube
In this video, I will show you how to make a progress bar in C# Console.+Need an Authenticator!?+Site: https://keyauth.com Github: ...
Read more >
c# - Console messages appearing in incorrect order when ...
Console output messages appear in an incorrect folder when they are populated by IProgress. var recounter = new IdRecounter(filePath, new ...
Read more >
Your Guide to the Python print() Function
Note: str() is a global built-in function that converts an object into its string representation. You can call it directly on any object,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found