Skip to content

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

@farag2

Description

@farag2

Windows Terminal version

1.22.10731.0

Windows build number

10.0.26100.3476

Other Software

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

	# Checking whether current terminal is Windows Terminal
	if ($env:WT_SESSION)
	{
		# https://github.com/microsoft/terminal/issues/14992
		[System.Console]::BufferHeight += $Menu.Count # a workaround for < 1.22 release
	}
	$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.4)

Recorded video with the bug

bug.mp4

Bare powershell.exe (5.1)

notbugged.mp4

The issue is fully similar to #14992, but the provided workaround has stopped working after Terminal 1.22 release.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-AttentionThe core contributors need to come back around and look at this ASAP.Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions