microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.96k stars 8.35k forks source link

New Line Mode does not work when use PSFzf #18263

Open mrbeardad opened 5 days ago

mrbeardad commented 5 days ago

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"

j4james commented 4 days ago

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

mrbeardad commented 4 days ago

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 4 days ago

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?