Windows Terminal breaks when the script hits the end of visible terminal window #19536

Open
opened 2026-01-31 06:46:28 +00:00 by claunia · 0 comments
Owner

Originally created by @farag2 on GitHub (Mar 14, 2023).

Windows Terminal version

1.16.10262.0

Windows build number

10.0.22621

Other Software

function ShowMenu
{
	[CmdletBinding()]
	param
	(
		[Parameter(Mandatory = $true)]
		[array]
		$Menu
	)

	$minY = [Console]::CursorTop
	$y = [Math]::Max([Math]::Min(1, $Menu.Count), 0)

	do
	{
		[Console]::CursorTop = $minY
		[Console]::CursorLeft = 0
		$i = 0
		foreach ($item in $Menu)
		{
			if ($i -ne $y)
			{
				Write-Information -MessageData ('  {1}  ' -f ($i+1), $item) -InformationAction Continue
			}
			else
			{
				Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue
			}
			$i++
		}

		$k = [Console]::ReadKey()
		switch ($k.Key)
		{
			"UpArrow"
			{
				if ($y -gt 0)
				{
					$y--
				}
			}
			"DownArrow"
			{
				if ($y -lt ($Menu.Count - 1))
				{
					$y++
				}
			}
			"Enter"
			{
				return $Menu[$y]
			}
		}
	}
	while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))

}

# Get disks letters
ShowMenu -Menu @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object)

Steps to reproduce

If we run this snippet that just shows disks letters, after we hit the end of visible windows area we cannot use brackets to choose: disks letters overlap each other when I use arrow down/up.

The bug is not reproducable neither in bare powershell.exe (5.1), nor in pwsh.exe (7.3)

Recorded video with the bug

https://user-images.githubusercontent.com/10544660/225085472-550932ac-49f2-4804-8fdf-cf36fbf99867.mp4

Bare powershell.exe (5.1)

https://user-images.githubusercontent.com/10544660/225085862-3c359282-e58c-4b92-88e8-cd45389d2cb5.mp4

Expected Behavior

Regardless we hit the visible console window, we disks letters shoudn't overlap each other.

Actual Behavior

Disks letters overlap each other in the console

Originally created by @farag2 on GitHub (Mar 14, 2023). ### Windows Terminal version 1.16.10262.0 ### Windows build number 10.0.22621 ### Other Software ```powershell function ShowMenu { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [array] $Menu ) $minY = [Console]::CursorTop $y = [Math]::Max([Math]::Min(1, $Menu.Count), 0) do { [Console]::CursorTop = $minY [Console]::CursorLeft = 0 $i = 0 foreach ($item in $Menu) { if ($i -ne $y) { Write-Information -MessageData (' {1} ' -f ($i+1), $item) -InformationAction Continue } else { Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue } $i++ } $k = [Console]::ReadKey() switch ($k.Key) { "UpArrow" { if ($y -gt 0) { $y-- } } "DownArrow" { if ($y -lt ($Menu.Count - 1)) { $y++ } } "Enter" { return $Menu[$y] } } } while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter)) } # Get disks letters ShowMenu -Menu @((Get-CimInstance -ClassName CIM_LogicalDisk | Where-Object -FilterScript {$_.DriveType -eq 3}).DeviceID | Sort-Object) ``` ### Steps to reproduce If we run this snippet that just shows disks letters, after we hit the end of visible windows area we cannot use brackets to choose: disks letters overlap each other when I use arrow down/up. The bug is not reproducable neither in bare powershell.exe (5.1), nor in pwsh.exe (7.3) Recorded video with the bug https://user-images.githubusercontent.com/10544660/225085472-550932ac-49f2-4804-8fdf-cf36fbf99867.mp4 Bare powershell.exe (5.1) https://user-images.githubusercontent.com/10544660/225085862-3c359282-e58c-4b92-88e8-cd45389d2cb5.mp4 ### Expected Behavior Regardless we hit the visible console window, we disks letters shoudn't overlap each other. ### Actual Behavior Disks letters overlap each other in the console
claunia added the Needs-TriageIssue-BugNeeds-Attention labels 2026-01-31 06:46:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19536