PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
623 stars 214 forks source link

Replace backtick-e with `$([char]0x1b)` #1961

Closed andyleejordan closed 1 year ago

andyleejordan commented 1 year ago

By replacing backtick-e with $([char]0x1b), we allow shell integration to work with Windows PowerShell, as the only problem seemed to be use of backtick-e, which was an escape character added only to PowerShell Core, but the [char] equivalent works fine.

Same change as proposed upstream in https://github.com/microsoft/vscode/pull/167023, resolves https://github.com/PowerShell/vscode-powershell/issues/4279.

andyleejordan commented 1 year ago

Thanks @SeeminglyScience for the spot!

Hrxn commented 1 year ago

Do I get this right, this is only a change for the sake of backward compatibility?

msftrncs commented 1 year ago

@Hrxn, Not necessarily backward compatible, more of a cross platform compatibility. Windows PowerShell is a still active currently supported platform. Consider that PowerShell Core is an enhanced platform, rather than a 'newer' version.

SeeminglyScience commented 1 year ago

Do I get this right, this is only a change for the sake of backward compatibility?

That's correct, the syntax `e only works in newer versions of PowerShell.

@Hrxn, Not necessarily backward compatible, more of a cross platform compatibility. Windows PowerShell is a still active currently supported platform. Consider that PowerShell Core is an enhanced platform, rather than a 'newer' version.

Windows PowerShell receives primarily only security updates. PowerShell 7 is definitely considered a newer version.

Hrxn commented 1 year ago

Thank you for this explanation, appreciate it. What I've always wondered, is there also some kind of performance difference between using "$([char]0x1b)<ANSI_Esc_Sequence>" and "backtick-e<ANSI_Esc_Sequence>" ?

I've done some tests here on my machine with Measure-Command, but I could not find any conclusive result somehow yet.. 🤷‍♂️

SeeminglyScience commented 1 year ago

Technically `e will be faster as it'll be emitted by the compiler as a constant. Not enough to really matter though, use `e where you don't need to support 5.1 since it's easier to read. Otherwise don't stress it

Hrxn commented 1 year ago

Thanks, glad that I finally found an answer for what has been a pretty longstanding question about powershell for me, to be honest.. 😉 Will use `e from now on, because I don't need/want to support 5.1

SeeminglyScience commented 1 year ago

Thanks, glad that I finally found an answer for what has been a pretty longstanding question about powershell for me, to be honest.. 😉 Will use `e from now on, because I don't need/want to support 5.1

If you aren't already there, check out the PowerShell Discord server. Plenty of folks hanging out ready to answer fun questions like that 😁