Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DISABLE_NEWLINE_AUTO_RETURN is not rest in some cases #3334

Open
5 tasks done
FallenGameR opened this issue Jun 17, 2023 · 3 comments
Open
5 tasks done

DISABLE_NEWLINE_AUTO_RETURN is not rest in some cases #3334

FallenGameR opened this issue Jun 17, 2023 · 3 comments

Comments

@FallenGameR
Copy link

  • 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:

image

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.

@FallenGameR
Copy link
Author

Some more context - I think the issue occurs more often if fzf call is interrupted with Ctrl+C.

@mrbeardad
Copy link

Is there any update?

@mrbeardad
Copy link

mrbeardad commented Dec 1, 2024

BTW it is easy to reproduce microsoft/terminal#18263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants