shithub: MicroHs

Download patch

ref: b79b7d62adda74efb45d69a8b88c268019d98e1a
parent: a6b8bf43eb49ff4de468061909ceda9efe3f4b11
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Oct 5 07:20:47 EDT 2023

Help message.

--- a/src/MicroHs/Interactive.hs
+++ b/src/MicroHs/Interactive.hs
@@ -21,12 +21,13 @@
 mainInteractive :: Flags -> IO ()
 mainInteractive flags = do
   putStrLn "Welcome to interactive MicroHs!"
-  putStrLn "Type ':quit' to quit"
+  putStrLn "Type ':quit' to quit, ':help' for help"
   _ <- S.runStateIO repl (preamble, flags, emptyCache)
   return ()
 
 preamble :: String
-preamble = "module " ++ interactiveName ++ "(module " ++ interactiveName ++ ") where\nimport Prelude\nimport Unsafe.Coerce\n"
+preamble = "module " ++ interactiveName ++ "(module " ++ interactiveName ++
+           ") where\nimport Prelude\nimport Unsafe.Coerce\n"
 
 repl :: I ()
 repl = S.do
@@ -70,7 +71,14 @@
       updateLines (unlines . filter (not . isPrefixOfBy eqChar del) . lines)
       S.return True
     )
+  , ("help", \ _ -> S.do
+      S.liftIO $ putStrLn helpText
+      S.return True
+    )
   ]
+
+helpText :: String
+helpText = "Commands:\n  :quit      quit MicroHs\n  :clear     clear all definitions\n  :delete d  delete definition(s) d\n  :help      this text\n  expr       evaluate expression\n  defn       add top level definition\n"
 
 updateLines :: (String -> String) -> I ()
 updateLines f = S.modify $ \ (ls, flgs, cache) -> (f ls, flgs, cache)
--