blob: bbde009af65507e96a295562c2d1f5ec23120b79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
module Readline
( readline, load_history )
where
-- Pick one of these:
-- GPL license
import qualified System.Console.Readline as RL
-- BSD license
--import qualified System.Console.Editline.Readline as RL
import System.Directory (getHomeDirectory)
import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout)
history_file = do
home <- getHomeDirectory
return $ home ++ "/.mal-history"
load_history = do
hfile <- history_file
content <- readFile hfile
mapM RL.addHistory (lines content)
readline prompt = do
hfile <- history_file
maybeLine <- RL.readline prompt
case maybeLine of
Just line -> do
appendFile hfile (line ++ "\n")
RL.addHistory line
return maybeLine
_ -> return maybeLine
|