mirror of
https://github.com/kanaka/mal.git
synced 2024-11-10 12:47:45 +03:00
5400d4bf5e
Achieve self-hosting!
33 lines
780 B
Haskell
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
|