1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/haskell/Readline.hs
Joel Martin c9de2e82ed Tests: add testing Dockerfile. Impl fixes.
- tests/docker/Dockerfile: specifies full docker image containing all
  tools/languages (except matlab).
- tests/docker-build.sh: build above image.
- tests/docker-run.sh: launch above image.
    Example: ./tests/docker-run.sh make test^js^step2
- Various fixes across multiple languages:
    - Unicode fixes for bash and R on Ubuntu Utopic
    - readline history fixes for when ~/.mal-history is not available
      or readable/writable. No fatal errors.
    - fixes to work with perl 5.20 (and still perl 5.18)
2015-03-11 22:22:35 -05:00

39 lines
982 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 Control.Monad (when)
import System.Directory (getHomeDirectory, doesFileExist)
import System.IO (hGetLine, hFlush, hIsEOF, stdin, stdout)
import System.IO.Error (tryIOError)
history_file = do
home <- getHomeDirectory
return $ home ++ "/.mal-history"
load_history = do
hfile <- history_file
fileExists <- doesFileExist hfile
when fileExists $ do
content <- readFile hfile
mapM RL.addHistory (lines content)
return ()
return ()
readline prompt = do
hfile <- history_file
maybeLine <- RL.readline prompt
case maybeLine of
Just line -> do
RL.addHistory line
res <- tryIOError (appendFile hfile (line ++ "\n"))
return maybeLine
_ -> return maybeLine