git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Make --single-line-mode the default behavior in psci
2cb85f6Phil Freeman
psci/Main.hs+16−14
@@ -13,7 +13,11 @@
13--
13--
14-----------------------------------------------------------------------------
14-----------------------------------------------------------------------------
15
15
16+{-# LANGUAGE DataKinds #-}
17+{-# LANGUAGE DoAndIfThenElse #-}
18+{-# LANGUAGE FlexibleContexts #-}
16−{-# LANGUAGE DataKinds, DoAndIfThenElse, FlexibleContexts, GeneralizedNewtypeDeriving #-}
19+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
20+{-# LANGUAGE RecordWildCards #-}
17
21
18module Main where
22module Main where
19
23
@@ -53,9 +57,8 @@ import qualified Paths_purescript as Paths
53import Commands as C
57import Commands as C
54import Parser
58import Parser
55
59
56−
57data PSCiOptions = PSCiOptions
60data PSCiOptions = PSCiOptions
58− { psciSingleLineFlag :: Bool
61+ { psciMultiLineMode :: Bool
59 , psciInputFile :: [FilePath]
62 , psciInputFile :: [FilePath]
60 }
63 }
61
64
@@ -182,8 +185,6 @@ prologueMessage = intercalate "\n"
182 , " |_| "
185 , " |_| "
183 , ""
186 , ""
184 , ":? shows help"
187 , ":? shows help"
185− , ""
186− , "Expressions are terminated using Ctrl+D"
187 ]
188 ]
188
189
189-- |
190-- |
@@ -599,32 +600,33 @@ loadUserConfig = do
599-- The PSCI main loop.
600-- The PSCI main loop.
600--
601--
601loop :: PSCiOptions -> IO ()
602loop :: PSCiOptions -> IO ()
602−loop (PSCiOptions singleLineMode files) = do
603+loop PSCiOptions{..} = do
603 config <- loadUserConfig
604 config <- loadUserConfig
604− modulesOrFirstError <- loadAllModules files
605+ modulesOrFirstError <- loadAllModules psciInputFile
605 case modulesOrFirstError of
606 case modulesOrFirstError of
606 Left err -> print err >> exitFailure
607 Left err -> print err >> exitFailure
607 Right modules -> do
608 Right modules -> do
608 historyFilename <- getHistoryFilename
609 historyFilename <- getHistoryFilename
609 let settings = defaultSettings { historyFile = Just historyFilename }
610 let settings = defaultSettings { historyFile = Just historyFilename }
610− flip evalStateT (PSCiState files defaultImports modules []) . runInputT (setComplete completion settings) $ do
611+ flip evalStateT (PSCiState psciInputFile defaultImports modules []) . runInputT (setComplete completion settings) $ do
611 outputStrLn prologueMessage
612 outputStrLn prologueMessage
612 traverse_ (mapM_ (runPSCI . handleCommand)) config
613 traverse_ (mapM_ (runPSCI . handleCommand)) config
613 go
614 go
614 where
615 where
615 go :: InputT (StateT PSCiState IO) ()
616 go :: InputT (StateT PSCiState IO) ()
616 go = do
617 go = do
617− c <- getCommand singleLineMode
618+ c <- getCommand (not psciMultiLineMode)
618 case c of
619 case c of
619 Left err -> outputStrLn err >> go
620 Left err -> outputStrLn err >> go
620 Right Nothing -> go
621 Right Nothing -> go
621 Right (Just Quit) -> outputStrLn quitMessage
622 Right (Just Quit) -> outputStrLn quitMessage
622 Right (Just c') -> runPSCI (loadAllImportedModules >> handleCommand c') >> go
623 Right (Just c') -> runPSCI (loadAllImportedModules >> handleCommand c') >> go
623
624
624−singleLineFlag :: Parser Bool
625+multiLineMode :: Parser Bool
625−singleLineFlag = switch $
626+multiLineMode = switch $
626− long "single-line-mode"
627+ long "multi-line-mode"
628+ <> short 'm'
627− <> Opts.help "Run in single-line mode"
629+ <> Opts.help "Run in multi-line mode (use ^D to terminate commands)"
628
630
629inputFile :: Parser FilePath
631inputFile :: Parser FilePath
630inputFile = strArgument $
632inputFile = strArgument $
@@ -632,7 +634,7 @@ inputFile = strArgument $
632 <> Opts.help "Optional .purs files to load on start"
634 <> Opts.help "Optional .purs files to load on start"
633
635
634psciOptions :: Parser PSCiOptions
636psciOptions :: Parser PSCiOptions
635−psciOptions = PSCiOptions <$> singleLineFlag
637+psciOptions = PSCiOptions <$> multiLineMode
636 <*> many inputFile
638 <*> many inputFile
637
639
638main :: IO ()
640main :: IO ()