git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add a :s import and :s loaded subcommand to respectively see the loaded
2689ec4Antoine R. Dumont
psci/Commands.hs+3−2
@@ -64,7 +64,7 @@ data Command
64 -- |
64 -- |
65 -- Show command
65 -- Show command
66 --
66 --
67− | Show
67+ | Show String
68
68
69-- |
69-- |
70-- The help menu.
70-- The help menu.
@@ -79,5 +79,6 @@ help =
79 , [":r ", "Reset"]
79 , [":r ", "Reset"]
80 , [":t <expr> ", "Show the type of <expr>"]
80 , [":t <expr> ", "Show the type of <expr>"]
81 , [":k <type> ", "Show the kind of <type>"]
81 , [":k <type> ", "Show the kind of <type>"]
82− , [":s ", "Show loaded modules" ]
82+ , [":s loaded ", "Show loaded modules" ]
83+ , [":s import ", "Show imported modules" ]
83 ]
84 ]
psci/Main.hs+17−3
@@ -305,14 +305,27 @@ handleDeclaration value = do
305 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
305 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
306 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
306 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
307
307
308−handleShowModules :: PSCI ()
308+-- |
309−handleShowModules = do
309+-- Show actual loaded modules in psci.
310+--
311+handleShowLoadedModules :: PSCI ()
312+handleShowLoadedModules = do
310 PSCiState { psciLoadedModules = loadedModules } <- PSCI $ lift get
313 PSCiState { psciLoadedModules = loadedModules } <- PSCI $ lift get
311 psciIO $ readModules loadedModules >>= putStrLn
314 psciIO $ readModules loadedModules >>= putStrLn
312 return ()
315 return ()
313 where readModules = return . unlines . nub . map toModuleName
316 where readModules = return . unlines . nub . map toModuleName
314 toModuleName = N.runModuleName . (\ (D.Module mdName _ _) -> mdName) . snd
317 toModuleName = N.runModuleName . (\ (D.Module mdName _ _) -> mdName) . snd
315
318
319+-- |
320+-- Show the imported modules in psci.
321+--
322+handleShowImportedModules :: PSCI ()
323+handleShowImportedModules = do
324+ PSCiState { psciImportedModuleNames = importedModuleNames } <- PSCI $ lift get
325+ psciIO $ readModules importedModuleNames >>= putStrLn
326+ return ()
327+ where readModules = return . unlines . map N.runModuleName
328+
316-- |
329-- |
317-- Imports a module, preserving the initial state on failure.
330-- Imports a module, preserving the initial state on failure.
318--
331--
@@ -455,7 +468,8 @@ handleCommand Reset = do
455handleCommand (TypeOf val) = handleTypeOf val
468handleCommand (TypeOf val) = handleTypeOf val
456handleCommand (KindOf typ) = handleKindOf typ
469handleCommand (KindOf typ) = handleKindOf typ
457handleCommand (Browse moduleName) = handleBrowse moduleName
470handleCommand (Browse moduleName) = handleBrowse moduleName
458−handleCommand Show = handleShowModules
471+handleCommand (Show "loaded") = handleShowLoadedModules
472+handleCommand (Show "import") = handleShowImportedModules
459handleCommand _ = PSCI $ outputStrLn "Unknown command"
473handleCommand _ = PSCI $ outputStrLn "Unknown command"
460
474
461singleLineFlag :: Cmd.Term Bool
475singleLineFlag :: Cmd.Term Bool
psci/Parser.hs+5−3
@@ -70,8 +70,10 @@ psciImport = Import <$> (char 'i' *> P.whiteSpace *> P.moduleName)
70--
70--
71psciLoadFile :: Parsec String P.ParseState Command
71psciLoadFile :: Parsec String P.ParseState Command
72psciLoadFile = LoadFile . trimEnd <$> (char 'm' *> P.whiteSpace *> manyTill anyChar eof)
72psciLoadFile = LoadFile . trimEnd <$> (char 'm' *> P.whiteSpace *> manyTill anyChar eof)
73− where
73+
74+-- | Trim end of input string
75+trimEnd :: String -> String
74− trimEnd = reverse . dropWhile isSpace . reverse
76+trimEnd = reverse . dropWhile isSpace . reverse
75
77
76-- |
78-- |
77-- Parses 'Commands.Quit' command.
79-- Parses 'Commands.Quit' command.
@@ -107,4 +109,4 @@ psciBrowse = Browse <$> (char 'b' *> P.whiteSpace *> P.moduleName)
107-- |
109-- |
108-- Show Command
110-- Show Command
109psciShowModules :: Parsec String P.ParseState Command
111psciShowModules :: Parsec String P.ParseState Command
110−psciShowModules = Show <$ char 's'
112+psciShowModules = Show . trimEnd <$> (char 's' *> P.whiteSpace *> manyTill anyChar eof)