Skip to content

Error when pasting a function into Windows Terminal #3397

@higbyk

Description

@higbyk

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 200 Keys:
 Space $ d a t a . S e t D a t a ( [ S y s t e m . W i n d o w s . F o r m s . D a t a F o r m a t s ] : : T e x t , Space $ u . N a m e ) Enter
 Space Space Space Space [ S y s t e m . W i n d o w s . F o r m s . C l i p b o a r d ] : : S e t D a t a O b j e c t ( $ d a t a ) Enter
 Space Space Space Space W r i t e - H o s t Space " $ ( $ u . N a m e ) Space ( $ ( $ u . U s e r P r i n c i p a l N a m e ) ) Space c o p i e d Space t o Space c l i p b o a r d " Enter
 }

Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -8.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------

Screenshot

image

Environment data

PS Version: 5.1.19041.1682
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.0.0-beta2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 127
BufferHeight: 30

Steps to reproduce

Paste the following into Windows Terminal:
`function Get-ADUserLink {
param (
[Parameter(Mandatory)]
[string[]]$UserName
)
# Lookup username as Name or SamAccountName
$UserName = $UserName -replace ' ',''
$u = foreach($server in 'hmm.REDACTED.net','okay.REDACTED.net','isee.REDACTED.net') {
Get-ADUser -Filter "(Name -like '$UserName
') -or (SamAccountName -like '$UserName*')" -Server $server |
Select-Object @{L='Name';E={$_.Name -replace '.',' '}},UserPrincipalName
}
if($u.Count -gt 1) {
$u = $u | Out-GridView -Title 'User Selection' -OutputMode Single
}
if(!$u) {
Write-Warning 'No records found!'
Exit
}

# Prepare formatted HTML for clipboard
$html = '

<html>
<body>
<!--StartFragment--><a title="im:'+$u.UserPrincipalName+'">'+$u.Name+'</a><!--EndFragment-->
</body>
</html>'
$header = "Version:1.0`nStartHTML:{0:d10}`nEndHTML:{1:d10}`nStartFragment:{2:d10}`nEndFragment:{3:d10}" -f ($html.IndexOf('<html>')+99),($html.Length+99),($html.IndexOf('<!--StartFragment-->')+20+99),($html.IndexOf('<!--EndFragment-->')+99)

# Set clipboard with formatted HTML
Add-Type -AssemblyName System.Windows.Forms
$data = New-Object System.Windows.Forms.DataObject
$data.SetData([System.Windows.Forms.DataFormats]::Html, $header + $html)
$data.SetData([System.Windows.Forms.DataFormats]::Text, $u.Name)
[System.Windows.Forms.Clipboard]::SetDataObject($data)
Write-Host "$($u.Name) ($($u.UserPrincipalName)) copied to clipboard"

}`

Expected behavior

It should just paste like normal.

Actual behavior

The above exception happens...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions