@@ -63,17 +63,10 @@ import System.Process (readProcessWithExitCode)
6363
6464-- | Command line options
6565data PSCiOptions = PSCiOptions
66− { psciMultiLineMode :: Bool
67− , psciInputFile :: [FilePath]
66+ { psciInputFile :: [FilePath]
6867 , psciBackend :: Backend
6968 }
7069
71−multiLineMode :: Opts.Parser Bool
72−multiLineMode = Opts.switch $
73− Opts.long "multi-line-mode"
74− <> Opts.short 'm'
75− <> Opts.help "Run in multi-line mode (use ^D to terminate commands)"
76−
7770inputFile :: Opts.Parser FilePath
7871inputFile = Opts.strArgument $
7972 Opts.metavar "FILE"
@@ -100,8 +93,7 @@ backend =
10093 <|> (nodeBackend <$> nodeFlagsFlag)
10194
10295psciOptions :: Opts.Parser PSCiOptions
103−psciOptions = PSCiOptions <$> multiLineMode
104− <*> many inputFile
96+psciOptions = PSCiOptions <$> many inputFile
10597 <*> backend
10698
10799version :: Opts.Parser (a -> a)
@@ -119,17 +111,20 @@ getOpt = Opts.execParser opts
119111 footerInfo = Opts.footer $ "psci " ++ showVersion Paths.version
120112
121113-- | Parses the input and returns either a command, or an error as a 'String'.
122−getCommand :: forall m. MonadException m => Bool -> InputT m (Either String (Maybe Command))
123−getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
124− firstLine <- withInterrupt $ getInputLine "> "
125− case firstLine of
114+getCommand :: forall m. MonadException m => InputT m (Either String (Maybe Command))
115+getCommand = handleInterrupt (return (Right Nothing)) $ do
116+ line <- withInterrupt $ getInputLine "> "
117+ case line of
126118 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
127119 Just "" -> return (Right Nothing)
128− Just s | singleLineMode || head s == ':' -> return . fmap Just $ parseCommand s
129− Just s -> fmap Just . parseCommand <$> go [s]
120+ Just s -> return . fmap Just $ parseCommand s
121+
122+pasteMode :: forall m. MonadException m => InputT m (Either String Command)
123+pasteMode =
124+ parseCommand <$> go []
130125 where
131126 go :: [String] -> InputT m String
132− go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine " "
127+ go ls = maybe (return . unlines $ reverse ls) (go . (:ls)) =<< getInputLine "… "
133128
134129-- | Make a JavaScript bundle for the browser.
135130bundle :: IO (Either Bundle.ErrorMessage String)
@@ -349,16 +344,28 @@ main = getOpt >>= loop
349344
350345 go :: state -> InputT (StateT PSCiState (ReaderT PSCiConfig IO)) ()
351346 go state = do
352− c <- getCommand (not psciMultiLineMode)
347+ c <- getCommand
353348 case c of
354349 Left err -> outputStrLn err >> go state
355350 Right Nothing -> go state
351+ Right (Just PasteLines) -> do
352+ c' <- pasteMode
353+ case c' of
354+ Left err -> outputStrLn err >> go state
355+ Right c'' -> handleCommandWithInterrupts state c''
356356 Right (Just QuitPSCi) -> do
357357 outputStrLn quitMessage
358358 liftIO $ shutdown state
359− Right (Just c') -> do
360− handleInterrupt (outputStrLn "Interrupted.")
361− (withInterrupt (lift (handleCommand (liftIO . eval state) (liftIO (reload state)) c')))
362− go state
359+ Right (Just c') -> handleCommandWithInterrupts state c'
360+
361+ handleCommandWithInterrupts
362+ :: state
363+ -> Command
364+ -> InputT (StateT PSCiState (ReaderT PSCiConfig IO)) ()
365+ handleCommandWithInterrupts state cmd = do
366+ handleInterrupt (outputStrLn "Interrupted.")
367+ (withInterrupt (lift (handleCommand (liftIO . eval state) (liftIO (reload state)) cmd)))
368+ go state
369+
363370 putStrLn prologueMessage
364371 setup >>= runner . go