cli: Replace embedStringFile with embedFile (compile with LC_ALL=C)

This commit is contained in:
Jakub Zárybnický 2018-08-24 14:03:19 +02:00 committed by Simon Michael
parent f108b56e61
commit 1190e2ae5d

View File

@ -22,6 +22,8 @@ module Hledger.Cli.DocFiles (
import Prelude () import Prelude ()
import "base-compat-batteries" Prelude.Compat import "base-compat-batteries" Prelude.Compat
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as BC
import Data.FileEmbed import Data.FileEmbed
import Data.String import Data.String
import System.IO import System.IO
@ -32,82 +34,82 @@ import Hledger.Utils (first3, second3, third3)
type Topic = String type Topic = String
docFiles :: IsString a => [(Topic, (a, a, a))] docFiles :: [(Topic, (ByteString, ByteString, ByteString))]
docFiles = [ docFiles = [
("hledger", ("hledger",
($(makeRelativeToProject "embeddedfiles/hledger.1" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger.1" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger.info" >>= embedFile)
)) ))
,("hledger-ui", ,("hledger-ui",
($(makeRelativeToProject "embeddedfiles/hledger-ui.1" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger-ui.1" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-ui.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-ui.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-ui.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-ui.info" >>= embedFile)
)) ))
,("hledger-web", ,("hledger-web",
($(makeRelativeToProject "embeddedfiles/hledger-web.1" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger-web.1" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-web.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-web.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-web.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-web.info" >>= embedFile)
)) ))
,("hledger-api", ,("hledger-api",
($(makeRelativeToProject "embeddedfiles/hledger-api.1" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger-api.1" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-api.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-api.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger-api.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger-api.info" >>= embedFile)
)) ))
,("journal", ,("journal",
($(makeRelativeToProject "embeddedfiles/hledger_journal.5" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger_journal.5" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_journal.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_journal.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_journal.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_journal.info" >>= embedFile)
)) ))
,("csv", ,("csv",
($(makeRelativeToProject "embeddedfiles/hledger_csv.5" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger_csv.5" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_csv.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_csv.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_csv.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_csv.info" >>= embedFile)
)) ))
,("timeclock", ,("timeclock",
($(makeRelativeToProject "embeddedfiles/hledger_timeclock.5" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger_timeclock.5" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_timeclock.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_timeclock.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_timeclock.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_timeclock.info" >>= embedFile)
)) ))
,("timedot", ,("timedot",
($(makeRelativeToProject "embeddedfiles/hledger_timedot.5" >>= embedStringFile) ($(makeRelativeToProject "embeddedfiles/hledger_timedot.5" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_timedot.txt" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_timedot.txt" >>= embedFile)
,$(makeRelativeToProject "embeddedfiles/hledger_timedot.info" >>= embedStringFile) ,$(makeRelativeToProject "embeddedfiles/hledger_timedot.info" >>= embedFile)
)) ))
] ]
docTopics :: [Topic] docTopics :: [Topic]
docTopics = map fst docFiles docTopics = map fst docFiles
lookupDocTxt :: IsString a => Topic -> a lookupDocTxt :: Topic -> ByteString
lookupDocTxt name = lookupDocTxt name =
maybe (fromString $ "No text manual found for topic: "++name) second3 $ lookup name docFiles maybe (fromString $ "No text manual found for topic: "++name) second3 $ lookup name docFiles
lookupDocNroff :: IsString a => Topic -> a lookupDocNroff :: Topic -> ByteString
lookupDocNroff name = lookupDocNroff name =
maybe (fromString $ "No man page found for topic: "++name) first3 $ lookup name docFiles maybe (fromString $ "No man page found for topic: "++name) first3 $ lookup name docFiles
lookupDocInfo :: IsString a => Topic -> a lookupDocInfo :: Topic -> ByteString
lookupDocInfo name = lookupDocInfo name =
maybe (fromString $ "No info manual found for topic: "++name) third3 $ lookup name docFiles maybe (fromString $ "No info manual found for topic: "++name) third3 $ lookup name docFiles
printHelpForTopic :: Topic -> IO () printHelpForTopic :: Topic -> IO ()
printHelpForTopic t = printHelpForTopic t =
putStrLn $ lookupDocTxt t BC.putStr (lookupDocTxt t)
runPagerForTopic :: FilePath -> Topic -> IO () runPagerForTopic :: FilePath -> Topic -> IO ()
runPagerForTopic exe t = do runPagerForTopic exe t = do
(Just inp, _, _, ph) <- createProcess (proc exe []){ (Just inp, _, _, ph) <- createProcess (proc exe []){
std_in=CreatePipe std_in=CreatePipe
} }
hPutStrLn inp (lookupDocTxt t) BC.hPutStrLn inp (lookupDocTxt t)
_ <- waitForProcess ph _ <- waitForProcess ph
return () return ()
runManForTopic :: Topic -> IO () runManForTopic :: Topic -> IO ()
runManForTopic t = runManForTopic t =
withSystemTempFile ("hledger-"++t++".nroff") $ \f h -> do withSystemTempFile ("hledger-"++t++".nroff") $ \f h -> do
hPutStrLn h $ lookupDocNroff t BC.hPutStrLn h $ lookupDocNroff t
hClose h hClose h
-- the temp file path will presumably have a slash in it, so man should read it -- the temp file path will presumably have a slash in it, so man should read it
callCommand $ "man " ++ f callCommand $ "man " ++ f
@ -115,7 +117,7 @@ runManForTopic t =
runInfoForTopic :: Topic -> IO () runInfoForTopic :: Topic -> IO ()
runInfoForTopic t = runInfoForTopic t =
withSystemTempFile ("hledger-"++t++".info") $ \f h -> do withSystemTempFile ("hledger-"++t++".info") $ \f h -> do
hPutStrLn h $ lookupDocInfo t BC.hPutStrLn h $ lookupDocInfo t
hClose h hClose h
callCommand $ "info " ++ f callCommand $ "info " ++ f