fix(pwsh): wrap keyhandlers in try/finally

This commit is contained in:
Jan De Dobbeleer 2023-11-01 12:23:37 +01:00 committed by Jan De Dobbeleer
parent 25cc389a33
commit 1f5d3ea90a

View file

@ -182,6 +182,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
if (("::TRANSIENT::" -eq "true") -and ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage")) {
Set-PSReadLineKeyHandler -Key Enter -BriefDescription 'OhMyPoshEnterKeyHandler' -ScriptBlock {
try {
$executingCommand = Set-TransientPrompt
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# Write FTCS_COMMAND_EXECUTED after accepting the input - it should still happen before execution
@ -189,13 +190,19 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
Write-Host "$([char]0x1b)]133;C`a" -NoNewline
}
}
finally {}
}
Set-PSReadLineKeyHandler -Key Ctrl+c -BriefDescription 'OhMyPoshCtrlCKeyHandler' -ScriptBlock {
try {
$start = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetSelectionState([ref]$start, [ref]$null)
# only render a transient prompt when no text is selected
if ($start -eq -1) {
Set-TransientPrompt
}
}
finally {}
[Microsoft.PowerShell.PSConsoleReadLine]::CopyOrCancelLine()
}
}
@ -209,7 +216,9 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
$executingCommand = $parseErrors.Count -eq 0
}
finally {}
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# Write FTCS_COMMAND_EXECUTED after accepting the input - it should still happen before execution
if ($executingCommand) {
Write-Host "$([char]0x1b)]133;C`a" -NoNewline