diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-01-05 17:03:19 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-01-10 13:22:30 -0500 |
commit | 6fe9b057396b4ace73106dc9c3c7fcb72a216bfa (patch) | |
tree | 47f2f6894108367b48e1bb4672688c636b5226b0 /driver/ghci | |
parent | e94b07dc791960439df18cfa600a2f42fc945336 (diff) | |
download | haskell-6fe9b057396b4ace73106dc9c3c7fcb72a216bfa.tar.gz |
Properly detect MinTTY when running GHCi on Windows
Before, we detecting the presence of MinTTY on Windows in a very
imprecise way: by checking if the `_` environment variable was set. Not
only is this easy to circumvent, but it also yields false positives on
terminals like ConEmu.
This changes the test to use the `GetFileInformationByHandleEx` function
instead, which provides a far more accurate check for MinTTY's presence.
I've tested this on PowerShell, MSYS2, Cygwin, ConEmu, and Git Bash, and
it does the right thing on each one.
Fixes #12958.
Test Plan: Run GHCi on many different Windows and MinTTY consoles
Reviewers: erikd, Phyx, austin, bgamari
Reviewed By: Phyx, bgamari
Subscribers: thomie, #ghc_windows_task_force
Differential Revision: https://phabricator.haskell.org/D2878
GHC Trac Issues: #12958
Diffstat (limited to 'driver/ghci')
-rw-r--r-- | driver/ghci/ghc.mk | 2 | ||||
-rw-r--r-- | driver/ghci/ghci.c | 5 |
2 files changed, 4 insertions, 3 deletions
diff --git a/driver/ghci/ghc.mk b/driver/ghci/ghc.mk index 240e16ff71..41d1f15c17 100644 --- a/driver/ghci/ghc.mk +++ b/driver/ghci/ghc.mk @@ -29,7 +29,7 @@ install_driver_ghci: else # Windows_Host... -driver/ghci_dist_C_SRCS = ghci.c ../utils/cwrapper.c ../utils/getLocation.c +driver/ghci_dist_C_SRCS = ghci.c ../utils/cwrapper.c ../utils/getLocation.c ../utils/isMinTTY.c driver/ghci_dist_CC_OPTS += -I driver/utils driver/ghci_dist_PROGNAME = ghci driver/ghci_dist_INSTALL = YES diff --git a/driver/ghci/ghci.c b/driver/ghci/ghci.c index f358d960d7..ebf13d8ba7 100644 --- a/driver/ghci/ghci.c +++ b/driver/ghci/ghci.c @@ -1,6 +1,7 @@ #include "cwrapper.h" #include "getLocation.h" +#include "isMinTTY.h" #include <stdio.h> #include <stdlib.h> #include <windows.h> @@ -15,8 +16,8 @@ int main(int argc, char** argv) { char *exePath; char *preArgv[1]; - if (getenv("_")) { - printf("WARNING: GHCi invoked via 'ghci.exe' in *nix-like shells (cygwin-bash, in particular)\n"); + if (isMinTTY()) { + printf("WARNING: GHCi invoked via 'ghci.exe' in MinTTY consoles (e.g., Cygwin or MSYS)\n"); printf(" doesn't handle Ctrl-C well; use the 'ghcii.sh' shell wrapper instead\n"); fflush(stdout); } |