1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/haskell/Readline.hs
Joel Martin 5400d4bf5e Haskell: add error handling and try*/catch*.
Achieve self-hosting!
2015-01-09 16:16:54 -06:00

33 lines
780 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)
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