@@ -63,17 +63,10 @@ import System.Process (readProcessWithExitCode)
64-- | Command line options
64-- | Command line options
65data PSCiOptions = PSCiOptions
65data PSCiOptions = PSCiOptions
66− { psciMultiLineMode :: Bool
67− , psciInputFile :: [FilePath]
66+ { psciInputFile :: [FilePath]
68 , psciBackend :: Backend
67 , psciBackend :: Backend
71−multiLineMode :: Opts.Parser Bool
72−multiLineMode = Opts.switch $
73− Opts.long "multi-line-mode"
75− <> Opts.help "Run in multi-line mode (use ^D to terminate commands)"
77inputFile :: Opts.Parser FilePath
70inputFile :: Opts.Parser FilePath
78inputFile = Opts.strArgument $
71inputFile = Opts.strArgument $
79 Opts.metavar "FILE"
72 Opts.metavar "FILE"
@@ -100,8 +93,7 @@ backend =
100 <|> (nodeBackend <$> nodeFlagsFlag)
93 <|> (nodeBackend <$> nodeFlagsFlag)
102psciOptions :: Opts.Parser PSCiOptions
95psciOptions :: Opts.Parser PSCiOptions
103−psciOptions = PSCiOptions <$> multiLineMode
96+psciOptions = PSCiOptions <$> many inputFile
105 <*> backend
97 <*> backend
107version :: Opts.Parser (a -> a)
99version :: Opts.Parser (a -> a)
@@ -119,17 +111,20 @@ getOpt = Opts.execParser opts
119 footerInfo = Opts.footer $ "psci " ++ showVersion Paths.version
111 footerInfo = Opts.footer $ "psci " ++ showVersion Paths.version
121-- | Parses the input and returns either a command, or an error as a 'String'.
113-- | 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))
114+getCommand :: forall m. MonadException m => InputT m (Either String (Maybe Command))
123−getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
115+getCommand = handleInterrupt (return (Right Nothing)) $ do
124− firstLine <- withInterrupt $ getInputLine "> "
116+ line <- withInterrupt $ getInputLine "> "
125− case firstLine of
117+ case line of
126 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
118 Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
127 Just "" -> return (Right Nothing)
119 Just "" -> return (Right Nothing)
128− Just s | singleLineMode || head s == ':' -> return . fmap Just $ parseCommand s
120+ Just s -> return . fmap Just $ parseCommand s
122+pasteMode :: forall m. MonadException m => InputT m (Either String Command)
129− Just s -> fmap Just . parseCommand <$> go [s]
124+ parseCommand <$> go []
131 go :: [String] -> InputT m String
126 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 "… "
134-- | Make a JavaScript bundle for the browser.
129-- | Make a JavaScript bundle for the browser.
135bundle :: IO (Either Bundle.ErrorMessage String)
130bundle :: IO (Either Bundle.ErrorMessage String)
@@ -349,16 +344,28 @@ main = getOpt >>= loop
350 go :: state -> InputT (StateT PSCiState (ReaderT PSCiConfig IO)) ()
345 go :: state -> InputT (StateT PSCiState (ReaderT PSCiConfig IO)) ()
351 go state = do
346 go state = do
352− c <- getCommand (not psciMultiLineMode)
347+ c <- getCommand
353 case c of
348 case c of
354 Left err -> outputStrLn err >> go state
349 Left err -> outputStrLn err >> go state
355 Right Nothing -> go state
350 Right Nothing -> go state
351+ Right (Just PasteLines) -> do
354+ Left err -> outputStrLn err >> go state
355+ Right c'' -> handleCommandWithInterrupts state c''
356 Right (Just QuitPSCi) -> do
356 Right (Just QuitPSCi) -> do
357 outputStrLn quitMessage
357 outputStrLn quitMessage
358 liftIO $ shutdown state
358 liftIO $ shutdown state
359− Right (Just c') -> do
359+ Right (Just c') -> handleCommandWithInterrupts state c'
361+ handleCommandWithInterrupts
364+ -> InputT (StateT PSCiState (ReaderT PSCiConfig IO)) ()
365+ handleCommandWithInterrupts state cmd = do
360− handleInterrupt (outputStrLn "Interrupted.")
366+ handleInterrupt (outputStrLn "Interrupted.")
361− (withInterrupt (lift (handleCommand (liftIO . eval state) (liftIO (reload state)) c')))
367+ (withInterrupt (lift (handleCommand (liftIO . eval state) (liftIO (reload state)) cmd)))
362− go state
368+ go state
363 putStrLn prologueMessage
370 putStrLn prologueMessage
364 setup >>= runner . go
371 setup >>= runner . go