haskell / win32

Haskell support for the Win32 API
http://hackage.haskell.org/package/Win32
Other
98 stars 62 forks source link

`System.Win32.MinTTY` doesn't detect newer versions of `mintty` (but perhaps that's OK) #216

Closed RyanGlScott closed 1 year ago

RyanGlScott commented 1 year ago

The functions in System.Win32.MinTTY are no longer able to detect newer versions of mintty. I'm not sure which version of mintty changed its behavior, but I can confirm this happening for mintty 3.6.1.

Current Behavior

isMinTTY will return False on mintty 3.6.1.

Currently, isMinTTY expects that STD_ERROR_HANDLE will always have FILE_TYPE_PIPE and uses GetFileInformationByHandleEx to query information about the pipe. On recent versions of mintty, however, STD_ERROR_HANDLE will instead have FILE_TYPE_CHAR. If I try to to use GetFileInformationByHandleEx on this version of STD_ERROR_HANDLE, it will fail with getFileInformationByHandleEx: invalid argument (Incorrect function.).

On the other hand, perhaps this isn't as bad as it sounds. One of the reasons why I wanted the ability to detect the presence of mintty in the first place is that in the past, mintty hasn't supported GHCi very well. Namely, you couldn't use tab completion, you couldn't use arrow keys to navigate through your command history, and Ctrl-C would completely bork GHCi. With recent versions of mintty, however, that all appears to be working as expected! That is to say: mintty and GHCi appear to get along just fine nowadays.

In light of this, perhaps we should just change the documentation for System.Win32.MinTTY to say that it only detects old versions of mintty? I'd consider that a satisfactory resolution, but perhaps there are other reasons one might want to detect mintty. If that is the case, we'd need a different way to detect it than what System.Win32.MinTTY is currently using.

Steps to Reproduce (for bugs)

To reproduce the bug, simply run isMinTTY using mintty 3.6.1, which is currently the latest version offered by MSYS2 at the time of writing.

$ mintty.exe --version
mintty 3.6.1 (x86_64-pc-msys)
© 2022 Thomas Wolff, Andy Koppe
License GPLv3+: GNU GPL version 3 or later
There is no warranty, to the extent permitted by law.

$ ghci
> import System.Win32.MinTTY
> isMinTTY
False

Your Environment

Mistuke commented 1 year ago

It's likely that wintty switched to using the Windows console PTY directly, so Conpty. Which is likely what caused the change in behavior. But if that's the case then it should be OK, that should interact correctly.

Did you observe anything breaking?

RyanGlScott commented 1 year ago

Did you observe anything breaking?

I haven't done a lot of testing, but everything that I've tried works remarkably well: GHCi history works, tab-completion works, command-line echoing is properly disabled when entering passwords, etc.

Mistuke commented 1 year ago

Yeah i suspect this is OK. Perhaps the function should have been named isEmulTTY but that ship has sailed. I think it's correct that it's returning false now.

RyanGlScott commented 1 year ago

In that case, I think the only thing left to do is to update the documentation. I've attempted to do so in #217.

Mistuke commented 1 year ago

Thanks, merged. I'll need to fix the docs generation after my deadline next week. I'll get back to fixing the mingw issue then too. Thanks!