Description
- I have read through the manual page (
man fzf
) - I have the latest version of fzf (0.41.1, latest available in chocolatey)
- I have searched through the existing issues
Info
- OS
- Windows
- Shell
- pwsh
Problem / Steps to reproduce
Occasionally after an fzf
call (that involves showing preview) the console (I repro'd this on Windows Terminal) enters some strange mode when it starts to interpret literally the carriage return CR
chars and makes them distinct from LF
chars:
After checking with Windows Terminal / Powershell / Console team it turned out that a wrong ConsoleMode is responsible for that kind of behavior. When I test it on a new tab the mode value is 7, but on a broken one it is 15:
$Kernel32 = Add-Type -Name 'Kernel32' -Namespace 'Win32' -PassThru -MemberDefinition '[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetStdHandle(int nStdHandle); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode); [DllImport("kernel32.dll", SetLastError = true)] public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint lpMode);'
[uint] $mode = 0
$Kernel32::GetConsoleMode($Kernel32::GetStdHandle(-11), [ref]$mode) | Out-Null; $mode
Setting the ConsoleMode back to 7 fixes the console:
$Kernel32::SetConsoleMode($Kernel32::GetStdHandle(-11), 0x7) | Out-Null
The difference in flags corresponds to DISABLE_NEWLINE_AUTO_RETURN flag that fzf initializes here and sets here.
My guess is that there are some conditions when fzf
sets the DISABLE_NEWLINE_AUTO_RETURN flag and then forgets to cleanup. And this makes the console almost unusable. Plus it is very hard to pin point what is wrong here (I had this problem for months and then accidentally learned the contacts of the Windows Terminal / Powershell / Console team who knew what can cause it).
Windows Terminal has a long-term work item to keep the ConsoleMode internally by itself, but this would not be implemented anytime soon.