Haskell: Add steps9-A, metadata, and atoms.
[jackhill/mal.git] / haskell / Readline.hs
CommitLineData
fa9a9758
JM
1module Readline
2( readline, load_history )
3where
4
5-- Pick one of these:
6-- GPL license
7import qualified System.Console.Readline as RL
8-- BSD license
9--import qualified System.Console.Editline.Readline as RL
10
11import System.Directory (getHomeDirectory)
12
13history_file = do
14 home <- getHomeDirectory
15 return $ home ++ "/.mal-history"
16
17load_history = do
18 hfile <- history_file
19 content <- readFile hfile
20 mapM RL.addHistory (lines content)
21
22readline prompt = do
23 hfile <- history_file
24 maybeLine <- RL.readline prompt
25 case maybeLine of
26 Just line -> do
27 appendFile hfile (line ++ "\n")
28 RL.addHistory line
29 return maybeLine
30 _ -> return maybeLine