git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Ghci-like handling of Ctrl-C, Ctrl-D in psci

- When Ctrl-C (UserInterrupt) is pressed, cancel the current input - When Ctrl-D (End of Input) is pressed: - if the input is empty interpret as "there would be no more commands, you may :quit" and quit - if the input isn't empty interpret as "the end of the current command" and execute the current command (whenether it's single-line or multi-line mode)

commite3177bfaae5a4244188019d32f3976e146084157 authorKonstantin Zudov <konstantin@anche.no> dateFri 25 Sep 2015, 20:58 (11 years ago) parent6fec8a0
1 file changed+3−3
psci/PSCi.hs+3−3
psci/PSCi.hs+3−3
@@ -437,10 +437,10 @@ handleKindOf typ = do
437437-- Parses the input and returns either a Metacommand, or an error as a string.
438438--
439439getCommand :: Bool -> InputT (StateT PSCiState IO) (Either String (Maybe Command))
440−getCommand singleLineMode = do
441− firstLine <- getInputLine "> "
440+getCommand singleLineMode = handleInterrupt (return (Right Nothing)) $ do
441+ firstLine <- withInterrupt $ getInputLine "> "
442442 case firstLine of
443− Nothing -> return (Right Nothing)
443+ Nothing -> return (Right (Just QuitPSCi)) -- Ctrl-D when input is empty
444444 Just "" -> return (Right Nothing)
445445 Just s | singleLineMode || head s == ':' -> return . either Left (Right . Just) $ parseCommand s
446446 Just s -> either Left (Right . Just) . parseCommand <$> go [s]