Skip to content

Commit

Permalink
fix(pwsh): wrap keyhandlers in try/finally
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Nov 1, 2023
1 parent 25cc389 commit 1f5d3ea
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/shell/scripts/omp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,27 @@ 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 {
$executingCommand = Set-TransientPrompt
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# Write FTCS_COMMAND_EXECUTED after accepting the input - it should still happen before execution
if (("::FTCS_MARKS::" -eq "true") -and $executingCommand) {
Write-Host "$([char]0x1b)]133;C`a" -NoNewline
try {
$executingCommand = Set-TransientPrompt
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# Write FTCS_COMMAND_EXECUTED after accepting the input - it should still happen before execution
if (("::FTCS_MARKS::" -eq "true") -and $executingCommand) {
Write-Host "$([char]0x1b)]133;C`a" -NoNewline
}
}
finally {}
}
Set-PSReadLineKeyHandler -Key Ctrl+c -BriefDescription 'OhMyPoshCtrlCKeyHandler' -ScriptBlock {
$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
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()
}
}
Expand All @@ -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
Expand Down

0 comments on commit 1f5d3ea

Please sign in to comment.