New Line Mode does not work when use PSFzf #22603

Closed
opened 2026-01-31 08:18:12 +00:00 by claunia · 4 comments
Owner

Originally created by @mrbeardad on GitHub (Nov 29, 2024).

Windows Terminal version

1.21.3231.0

Windows build number

10.0.22631.0

Other Software

PowerShell 7.4.6
PSFzf 2.6.7

Steps to reproduce

Install PSFzf by Import-Module PSFzf, then set the content of powershell $PROFILE to following

Set-PSReadLineKeyHandler -Key Tab -ScriptBlock {
  Invoke-FzfTabCompletion
}
return
  1. type any command ant press tab to complete until the bug appear
  2. it seams like "new line mode" does not work well, outputing "`e[20h" to enable "newline mode" could fix this, but not always

https://github.com/user-attachments/assets/c9993e7d-478a-48e4-a749-a95b5ec0815e

Expected Behavior

"`e[20h" set to "newline mode"

Actual Behavior

still in "linefeed mode"

Originally created by @mrbeardad on GitHub (Nov 29, 2024). ### Windows Terminal version 1.21.3231.0 ### Windows build number 10.0.22631.0 ### Other Software PowerShell 7.4.6 PSFzf 2.6.7 ### Steps to reproduce Install PSFzf by `Import-Module PSFzf`, then set the content of powershell $PROFILE to following ```ps1 Set-PSReadLineKeyHandler -Key Tab -ScriptBlock { Invoke-FzfTabCompletion } return ``` 1. type any command ant press `tab` to complete until the bug appear 2. it seams like "new line mode" does not work well, outputing "`e[20h" to enable "newline mode" could fix this, but not always https://github.com/user-attachments/assets/c9993e7d-478a-48e4-a749-a95b5ec0815e ### Expected Behavior "`e[20h" set to "newline mode" ### Actual Behavior still in "linefeed mode"
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 08:18:12 +00:00
Author
Owner

@j4james commented on GitHub (Nov 30, 2024):

What you're seeing is most likely the result of the console mode DISABLE_NEWLINE_AUTO_RETURN rather than the ANSI newline mode 20. There is an open issue for fzf that suggests they may be setting the mode but not always cleaning up afterwards. See https://github.com/junegunn/fzf/issues/3334

@j4james commented on GitHub (Nov 30, 2024): What you're seeing is most likely the result of the console mode `DISABLE_NEWLINE_AUTO_RETURN` rather than the ANSI newline mode 20. There is an open issue for `fzf` that suggests they may be setting the mode but not always cleaning up afterwards. See https://github.com/junegunn/fzf/issues/3334
Author
Owner

@mrbeardad commented on GitHub (Nov 30, 2024):

I'm not sure about this, but it seems DISABLE_NEWLINE_AUTO_RETURN (0x0008) is unset.

#include <iostream>
#include <windows.h>

int main(int argc, char* argv[])
{
  auto ih = GetStdHandle(STD_INPUT_HANDLE);
  DWORD mode = 0;
  GetConsoleMode(ih, &mode);
  std::cout << "stdin mode: 0x" << std::hex << mode << std::endl;
  auto oh = GetStdHandle(STD_OUTPUT_HANDLE);
  mode = 0;
  GetConsoleMode(oh, &mode);
  std::cout << "stdout mode: 0x" << std::hex << mode << std::endl;
}

Image

@mrbeardad commented on GitHub (Nov 30, 2024): I'm not sure about this, but it seems `DISABLE_NEWLINE_AUTO_RETURN` (0x0008) is unset. ```cpp #include <iostream> #include <windows.h> int main(int argc, char* argv[]) { auto ih = GetStdHandle(STD_INPUT_HANDLE); DWORD mode = 0; GetConsoleMode(ih, &mode); std::cout << "stdin mode: 0x" << std::hex << mode << std::endl; auto oh = GetStdHandle(STD_OUTPUT_HANDLE); mode = 0; GetConsoleMode(oh, &mode); std::cout << "stdout mode: 0x" << std::hex << mode << std::endl; } ``` ![Image](https://github.com/user-attachments/assets/ecce049b-82bb-4748-9d0d-288c97508a04)
Author
Owner

@mrbeardad commented on GitHub (Nov 30, 2024):

I got console mode as 0xf by the code in the https://github.com/junegunn/fzf/issues/3334, I don't understand why it is different than native code?

@mrbeardad commented on GitHub (Nov 30, 2024): I got console mode as `0xf` by the code in the https://github.com/junegunn/fzf/issues/3334, I don't understand why it is different than native code?
Author
Owner

@carlos-zamora commented on GitHub (Dec 11, 2024):

Thanks for filing! We think this is a bug on Invoke-FzfTabCompletion or PSReadline/PowerShell. PSReadline is equipped to save and restore the console mode before launching the command at the prompt, but it may not be prepared to do so during tab completion.

This looks suspicious:
3f31db0367/PSFzf.Base.ps1 (L122-L135)

Either way, the issue isn't in our codebase. Hope this helps!

@carlos-zamora commented on GitHub (Dec 11, 2024): Thanks for filing! We think this is a bug on `Invoke-FzfTabCompletion` or PSReadline/PowerShell. PSReadline is equipped to save and restore the console mode before launching the command at the prompt, but it may not be prepared to do so during tab completion. This looks suspicious: https://github.com/kelleyma49/PSFzf/blob/3f31db0367a4865378cc9f667dd3f679d2590c6f/PSFzf.Base.ps1#L122-L135 Either way, the issue isn't in our codebase. Hope this helps!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22603