Commit | Line | Data |
---|---|---|
fa9a9758 JM |
1 | module Readline |
2 | ( readline, load_history ) | |
3 | where | |
4 | ||
5 | -- Pick one of these: | |
6 | -- GPL license | |
7 | import qualified System.Console.Readline as RL | |
8 | -- BSD license | |
9 | --import qualified System.Console.Editline.Readline as RL | |
10 | ||
11 | import System.Directory (getHomeDirectory) | |
12 | ||
13 | history_file = do | |
14 | home <- getHomeDirectory | |
15 | return $ home ++ "/.mal-history" | |
16 | ||
17 | load_history = do | |
18 | hfile <- history_file | |
19 | content <- readFile hfile | |
20 | mapM RL.addHistory (lines content) | |
21 | ||
22 | readline 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 |