1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-13 11:23:59 +03:00
mal/haskell/Readline.hs

31 lines
720 B
Haskell

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)
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