Merge pull request #747 from atom-haskell/fix-stdin-encoding

Add option for stdio encoding, set stdin, stderr encoding
This commit is contained in:
Nikolay Yakimov 2016-02-09 14:36:30 +03:00
commit 721951e32c
3 changed files with 13 additions and 4 deletions

View File

@ -105,6 +105,7 @@ data Options = Options {
-- | GHC command line options set on the @ghc-mod@ command line -- | GHC command line options set on the @ghc-mod@ command line
, optGhcUserOptions :: [GHCOption] , optGhcUserOptions :: [GHCOption]
, optFileMappings :: [(FilePath, Maybe FilePath)] , optFileMappings :: [(FilePath, Maybe FilePath)]
, optEncoding :: String
} deriving (Show) } deriving (Show)
-- | A default 'Options'. -- | A default 'Options'.
@ -124,6 +125,7 @@ defaultOptions = Options {
} }
, optGhcUserOptions = [] , optGhcUserOptions = []
, optFileMappings = [] , optFileMappings = []
, optEncoding = "UTF-8"
} }
---------------------------------------------------------------- ----------------------------------------------------------------

View File

@ -34,9 +34,12 @@ handler = flip gcatches
] ]
main :: IO () main :: IO ()
main = do main =
hSetEncoding stdout utf8 parseArgs >>= \res@(globalOptions, _) -> do
parseArgs >>= \res@(globalOptions, _) -> enc <- mkTextEncoding $ optEncoding globalOptions
hSetEncoding stdout enc
hSetEncoding stderr enc
hSetEncoding stdin enc
catches (progMain res) [ catches (progMain res) [
Handler $ \(e :: GhcModError) -> Handler $ \(e :: GhcModError) ->
runGmOutT globalOptions $ exitError $ renderStyle ghcModStyle (gmeDoc e) runGmOutT globalOptions $ exitError $ renderStyle ghcModStyle (gmeDoc e)
@ -107,7 +110,6 @@ getFileSourceFromStdin = do
then fmap (x:) readStdin' then fmap (x:) readStdin'
else return [] else return []
-- Someone please already rewrite the cmdline parsing code *weep* :'(
wrapGhcCommands :: (IOish m, GmOut m) => Options -> GhcModCommands -> m () wrapGhcCommands :: (IOish m, GmOut m) => Options -> GhcModCommands -> m ()
wrapGhcCommands _opts CmdRoot = gmPutStr =<< rootInfo wrapGhcCommands _opts CmdRoot = gmPutStr =<< rootInfo
wrapGhcCommands opts cmd = wrapGhcCommands opts cmd =

View File

@ -174,6 +174,11 @@ globalArgSpec = Options
<=> metavar "OPT" <=> metavar "OPT"
<=> help "Option to be passed to GHC" <=> help "Option to be passed to GHC"
<*> many fileMappingSpec <*> many fileMappingSpec
<*> strOption
$$ long "encoding"
<=> value "UTF-8"
<=> showDefault
<=> help "I/O encoding"
where where
fileMappingSpec = fileMappingSpec =
getFileMapping . splitOn '=' <$> strOption getFileMapping . splitOn '=' <$> strOption