on master help sign in
add locale munging in tutd.hs

in docker, the locale data may be missing, leading to an encoding error when tutd prints a table (non-ASCII) data force UTF-8 iff the locale is ASCII

commit3ed860096dd7301978910ad61f1cc1a81422073b authorA.M <agentm@themactionfaction.com> dateFri 31 Jul 2020, 01:07 (6 years ago) parent7d3b924
1 file changed+10
src/bin/TutorialD/tutd.hs+10
src/bin/TutorialD/tutd.hs+10
@@ -5,8 +5,11 @@ import ProjectM36.Client
55import ProjectM36.Server.ParseArgs
66import ProjectM36.Server
77import System.IO
8+import GHC.IO.Encoding
89import Options.Applicative
910import System.Exit
11+import System.Environment
12+import Control.Monad
1013#if __GLASGOW_HASKELL__ < 804
1114import Data.Monoid
1215#endif
@@ -86,8 +89,15 @@ printWelcome = do
8689 putStrLn "A full tutorial is available at:"
8790 putStrLn "https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown"
8891
92+-- | If the locale is set to ASCII, upgrade it to UTF-8 because tutd outputs UTF-8-encoded attributes. This is especially important in light docker images where the locale data may be missing.
93+setLocaleIfNecessary :: IO ()
94+setLocaleIfNecessary = do
95+ l <- getLocaleEncoding
96+ when (textEncodingName l == "ASCII") (setLocaleEncoding utf8)
97+
8998main :: IO ()
9099main = do
100+ setLocaleIfNecessary
91101 interpreterConfig <- execParser opts
92102 let connInfo = connectionInfoForConfig interpreterConfig
93103 fscheck <- checkFSType (checkFSForConfig interpreterConfig) (fromMaybe NoPersistence (persistenceStrategyForConfig interpreterConfig))