|
| 1 | +{-# LANGUAGE CPP #-} |
1 | 2 | {-# LANGUAGE OverloadedStrings #-} |
2 | 3 | {-# LANGUAGE ScopedTypeVariables #-} |
3 | 4 | {-# LANGUAGE FlexibleContexts #-} |
@@ -73,10 +74,31 @@ import System.FilePath (dropTrailingPathSeparator) |
73 | 74 | import System.IO (hIsTerminalDevice, stderr, stdin, stdout, hSetBuffering, BufferMode(..)) |
74 | 75 | import System.Process.Read |
75 | 76 |
|
| 77 | +#if WINDOWS |
| 78 | +import System.Win32.Console (setConsoleCP, setConsoleOutputCP, getConsoleCP, getConsoleOutputCP) |
| 79 | +import System.IO (hSetEncoding, utf8, hPutStrLn) |
| 80 | +#endif |
| 81 | + |
76 | 82 | -- | Commandline dispatcher. |
77 | 83 | main :: IO () |
78 | | -main = withInterpreterArgs stackProgName $ \args isInterpreter -> |
79 | | - do -- Line buffer the output by default, particularly for non-terminal runs. |
| 84 | +main = withInterpreterArgs stackProgName $ \args isInterpreter -> do |
| 85 | +#if WINDOWS |
| 86 | + -- Set the code page for this process to 65001 (UTF-8). See: |
| 87 | + -- https://github.com/commercialhaskell/stack/issues/738 |
| 88 | + origCPI <- getConsoleCP |
| 89 | + origCPO <- getConsoleOutputCP |
| 90 | + |
| 91 | + when (origCPI /= 65001 || origCPO /= 65001) $ do |
| 92 | + hPutStrLn stderr |
| 93 | + "Setting codepage to UTF-8 (65001) to ensure correct output from GHC" |
| 94 | + setConsoleCP 65001 |
| 95 | + setConsoleOutputCP 65001 |
| 96 | + hSetEncoding stdin utf8 |
| 97 | + hSetEncoding stdout utf8 |
| 98 | + hSetEncoding stderr utf8 |
| 99 | +#endif |
| 100 | + |
| 101 | + -- Line buffer the output by default, particularly for non-terminal runs. |
80 | 102 | -- See https://github.com/commercialhaskell/stack/pull/360 |
81 | 103 | hSetBuffering stdout LineBuffering |
82 | 104 | hSetBuffering stdin LineBuffering |
|
0 commit comments