Permalink
Browse files

ENH Workaround for systems with poor locale support

  • Loading branch information...
luispedro committed May 11, 2018
1 parent 42b2cd0 commit cb6f786ab8ef485913af641c7310b335c17109d0
Showing with 15 additions and 3 deletions.
  1. +3 −0 ChangeLog
  2. +12 −3 Execs/Main.hs
View
@@ -1,3 +1,6 @@
Version 0.8.0+
* Add fallback for character encoding on systems with bad locale support
Version 0.8.0 2018-05-06 by luispedro
* Add minimap2 support as alternative mapper
* Faster collect()
View
@@ -41,13 +41,12 @@ import Options.Applicative
import System.FilePath
import System.Directory
import Control.Monad.Extra (whenJust)
import System.IO (stderr, hPutStrLn)
import System.IO (stdout, stderr, stdin, hPutStrLn, mkTextEncoding, hGetEncoding, Handle, hSetEncoding)
import Control.Exception (catch, IOException, try)
import Control.Concurrent (setNumCapabilities)
import System.Console.ANSI (setSGRCode, SGR(..), ConsoleLayer(..), Color(..), ColorIntensity(..))
import System.Exit (exitSuccess, exitFailure)
import Control.Monad.Trans.Except
import Control.Monad.Trans.Resource
import qualified Data.Text as T
@@ -366,7 +365,17 @@ main' = do
updateNglEnvironment' (\env -> env { ngleConfiguration = config })
modeExec (mode args)
main = catch main' $ \e -> do
makeEncodingSafe :: Handle -> IO ()
makeEncodingSafe h = do
ce' <- hGetEncoding h
case ce' of
Nothing -> return ()
Just ce -> mkTextEncoding (takeWhile (/= '/') (show ce) ++ "//TRANSLIT") >>=
hSetEncoding h
main = do
mapM_ makeEncodingSafe [stdout, stdin, stderr]
catch main' $ \e -> do
putStrLn ("Exiting after internal error. If you can reproduce this issue, please run your script "++
"with the --trace flag and report a bug at http://github.com/luispedro/ngless/issues")
print (e :: IOException)

0 comments on commit cb6f786

Please sign in to comment.